diff --git a/build_files/scons/config/win32-mingw-config.py b/build_files/scons/config/win32-mingw-config.py index f61b128fe9f..95b2329f426 100644 --- a/build_files/scons/config/win32-mingw-config.py +++ b/build_files/scons/config/win32-mingw-config.py @@ -178,7 +178,7 @@ BF_RAYOPTIMIZATION_SSE_FLAGS = ['-msse'] #CUDA WITH_BF_CYCLES_CUDA_BINARIES = False #BF_CYCLES_CUDA_NVCC = "" # Path to the nvidia compiler -BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_20', 'sm_21'] # don't build sm_13 until the compile can fit in 32bit process again :) +BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21', 'sm_30'] ## CC = 'gcc' diff --git a/build_files/scons/config/win64-mingw-config.py b/build_files/scons/config/win64-mingw-config.py index 6848d78d959..c2bf2df6d00 100644 --- a/build_files/scons/config/win64-mingw-config.py +++ b/build_files/scons/config/win64-mingw-config.py @@ -151,7 +151,7 @@ BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib' WITH_BF_CYCLES = True WITH_BF_CYCLES_CUDA_BINARIES = False BF_CYCLES_CUDA_NVCC = "" # Path to the NVIDIA CUDA compiler -BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21'] +BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21', 'sm_30'] WITH_BF_OIIO = True BF_OIIO = LIBDIR + '/openimageio' diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index 805954968b9..186f67b0df6 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -849,7 +849,7 @@ def pymodule2sphinx(basepath, module_name, module, title): elif value_type in (bool, int, float, str, tuple): # constant, not much fun we can do here except to list it. # TODO, figure out some way to document these! - #fw(".. data:: %s\n\n" % attribute) + fw(".. data:: %s\n\n" % attribute) write_indented_lines(" ", fw, "constant value %s" % repr(value), False) fw("\n") else: diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index 697427081c3..337eebe4be0 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -20,8 +20,8 @@ elseif(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math") endif() -# for OSL, not needed yet -# set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID") +# for OSL +set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID") # set(RTTI_DISABLE_FLAGS "/GR- -DBOOST_NO_RTTI -DBOOST_NO_TYPEID") # Definitions and Includes diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp index 922a96dc4df..87a238e508c 100644 --- a/intern/cycles/app/cycles_xml.cpp +++ b/intern/cycles/app/cycles_xml.cpp @@ -487,6 +487,7 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug else if(string_iequals(node.name(), "mix")) { MixNode *mix = new MixNode(); xml_read_enum(&mix->type, MixNode::type_enum, node, "type"); + xml_read_bool(&mix->use_clamp, node, "use_clamp"); snode = mix; } else if(string_iequals(node.name(), "gamma")) { @@ -518,6 +519,7 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug else if(string_iequals(node.name(), "math")) { MathNode *math = new MathNode(); xml_read_enum(&math->type, MathNode::type_enum, node, "type"); + xml_read_bool(&math->use_clamp, node, "use_clamp"); snode = math; } else if(string_iequals(node.name(), "vector_math")) { diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 561ccbbe3d1..885b488a3ea 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -927,6 +927,9 @@ def draw_device(self, context): layout.prop(cscene, "device") elif device_type == 'OPENCL' and cscene.feature_set == 'EXPERIMENTAL': layout.prop(cscene, "device") + + if cscene.feature_set == 'EXPERIMENTAL' and cscene.device == 'CPU' and engine.with_osl(): + layout.prop(cscene, "shading_system") def draw_pause(self, context): diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 813314f67a6..fd9f836eec0 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -247,11 +247,10 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, scene->object_manager->tag_update(scene); } - /* updated dupli objects require particle sync */ - bool need_particle_update = object_need_particle_update(b_ob); - /* object sync */ - if(object_updated || (object->mesh && object->mesh->need_update) || need_particle_update) { + /* transform comparison should not be needed, but duplis don't work perfect + * in the depsgraph and may not signal changes, so this is a workaround */ + if(object_updated || (object->mesh && object->mesh->need_update) || tfm != object->tfm) { object->name = b_ob.name().c_str(); object->pass_id = b_ob.pass_index(); object->tfm = tfm; @@ -277,10 +276,6 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, object->particle_id = particle_id; - /* particle sync */ - if (need_particle_update) - sync_particles(object, b_ob); - object->tag_update(scene); } } @@ -303,7 +298,7 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion) /* object loop */ BL::Scene::objects_iterator b_ob; BL::Scene b_sce = b_scene; - int particle_offset = 0; + int particle_offset = 1; /* first particle is dummy for regular, non-instanced objects */ bool cancel = false; diff --git a/intern/cycles/blender/blender_particles.cpp b/intern/cycles/blender/blender_particles.cpp index e32c80a51b5..177912cd8f0 100644 --- a/intern/cycles/blender/blender_particles.cpp +++ b/intern/cycles/blender/blender_particles.cpp @@ -16,9 +16,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "object.h" - #include "mesh.h" +#include "particles.h" + #include "blender_sync.h" #include "blender_util.h" @@ -31,7 +31,7 @@ CCL_NAMESPACE_BEGIN /* Particles Sync */ -bool BlenderSync::object_need_particle_update(BL::Object b_ob) +bool BlenderSync::psys_need_update(BL::ParticleSystem b_psys) { /* Particle data is only needed for * a) Billboard render mode if object's own material uses particle info @@ -41,9 +41,7 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) */ bool need_update = false; - BL::Object::particle_systems_iterator b_psys; - for (b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { - switch (b_psys->settings().render_type()) { + switch (b_psys.settings().render_type()) { /* XXX not implemented yet! * billboards/strands would become part of the mesh data (?), * so the mesh attributes would store whether particle info is required. @@ -61,7 +59,7 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) #endif case BL::ParticleSettings::render_type_OBJECT: { - BL::Object b_dupli_ob = b_psys->settings().dupli_object(); + BL::Object b_dupli_ob = b_psys.settings().dupli_object(); if (b_dupli_ob) { BL::ID key = (BKE_object_is_modified(b_dupli_ob))? b_dupli_ob: b_dupli_ob.data(); Mesh *mesh = mesh_map.find(key); @@ -73,7 +71,7 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) } case BL::ParticleSettings::render_type_GROUP: { - BL::Group b_dupli_group = b_psys->settings().dupli_group(); + BL::Group b_dupli_group = b_psys.settings().dupli_group(); if (b_dupli_group) { BL::Group::objects_iterator b_gob; for (b_dupli_group.objects.begin(b_gob); b_gob != b_dupli_group.objects.end(); ++b_gob) { @@ -90,7 +88,6 @@ bool BlenderSync::object_need_particle_update(BL::Object b_ob) default: /* avoid compiler warning */ break; - } } return need_update; @@ -114,7 +111,19 @@ static bool use_particle_system(BL::ParticleSystem b_psys) static bool use_particle(BL::Particle b_pa) { - return b_pa.is_exist() && b_pa.is_visible() && b_pa.alive_state()==BL::Particle::alive_state_ALIVE; + return b_pa.is_exist() && b_pa.is_visible() && + (b_pa.alive_state()==BL::Particle::alive_state_ALIVE || b_pa.alive_state()==BL::Particle::alive_state_DYING); +} + +static int psys_count_particles(BL::ParticleSystem b_psys) +{ + int tot = 0; + BL::ParticleSystem::particles_iterator b_pa; + for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa) { + if(use_particle(*b_pa)) + ++tot; + } + return tot; } int BlenderSync::object_count_particles(BL::Object b_ob) @@ -122,45 +131,89 @@ int BlenderSync::object_count_particles(BL::Object b_ob) int tot = 0; BL::Object::particle_systems_iterator b_psys; for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { - if (use_particle_system(*b_psys)) { - BL::ParticleSystem::particles_iterator b_pa; - for(b_psys->particles.begin(b_pa); b_pa != b_psys->particles.end(); ++b_pa) { - if(use_particle(*b_pa)) - ++tot; - } - } + if (use_particle_system(*b_psys)) + tot += psys_count_particles(*b_psys); } return tot; } -void BlenderSync::sync_particles(Object *ob, BL::Object b_ob) +void BlenderSync::sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys) { - int tot = object_count_particles(b_ob); + /* depending on settings the psys may not even be rendered */ + if (!use_particle_system(b_psys)) + return; - ob->particles.clear(); - ob->particles.reserve(tot); + /* key to lookup particle system */ + ParticleSystemKey key(b_ob, b_psys); + ParticleSystem *psys; - int index; - BL::Object::particle_systems_iterator b_psys; - for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { - if (use_particle_system(*b_psys)) { - int pa_index = 0; - BL::ParticleSystem::particles_iterator b_pa; - for(b_psys->particles.begin(b_pa), index = 0; b_pa != b_psys->particles.end(); ++b_pa, ++index) { - if(use_particle(*b_pa)) { - Particle pa; - - pa.index = pa_index; - pa.age = b_scene.frame_current() - b_pa->birth_time(); - pa.lifetime = b_pa->lifetime(); - - ob->particles.push_back(pa); - } + /* test if we need to sync */ + bool object_updated = false; + + if(particle_system_map.sync(&psys, b_ob, b_ob, key)) + object_updated = true; + + bool need_update = psys_need_update(b_psys); + + if (object_updated || need_update) { + int tot = psys_count_particles(b_psys); + psys->particles.clear(); + psys->particles.reserve(tot); + + int index = 0; + BL::ParticleSystem::particles_iterator b_pa; + for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa) { + if(use_particle(*b_pa)) { + Particle pa; - ++pa_index; + pa.index = index; + pa.age = b_scene.frame_current() - b_pa->birth_time(); + pa.lifetime = b_pa->lifetime(); + pa.location = get_float3(b_pa->location()); + pa.rotation = get_float4(b_pa->rotation()); + pa.size = b_pa->size(); + pa.velocity = get_float3(b_pa->velocity()); + pa.angular_velocity = get_float3(b_pa->angular_velocity()); + + psys->particles.push_back(pa); } + + ++index; } + + psys->tag_update(scene); } } +void BlenderSync::sync_particle_systems() +{ + /* layer data */ + uint scene_layer = render_layer.scene_layer; + + particle_system_map.pre_sync(); + + /* object loop */ + BL::Scene::objects_iterator b_ob; + BL::Scene b_sce = b_scene; + + for(; b_sce; b_sce = b_sce.background_set()) { + for(b_sce.objects.begin(b_ob); b_ob != b_sce.objects.end(); ++b_ob) { + bool hide = (render_layer.use_viewport_visibility)? b_ob->hide(): b_ob->hide_render(); + uint ob_layer = get_layer(b_ob->layers(), b_ob->layers_local_view(), object_is_light(*b_ob)); + CYCLES_LOCAL_LAYER_HACK(render_layer.use_localview, ob_layer); + hide = hide || !(ob_layer & scene_layer); + + if(!hide) { + BL::Object::particle_systems_iterator b_psys; + for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) + sync_particles(*b_ob, *b_psys); + } + } + } + + /* handle removed data and modified pointers */ + if(particle_system_map.post_sync()) + scene->particle_system_manager->tag_update(scene); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 2309cc6eb40..9758d9bf92a 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -221,6 +221,7 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph BL::ShaderNodeMixRGB b_mix_node(b_node); MixNode *mix = new MixNode(); mix->type = MixNode::type_enum[b_mix_node.blend_type()]; + mix->use_clamp = b_mix_node.use_clamp(); node = mix; break; } @@ -244,6 +245,7 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph BL::ShaderNodeMath b_math_node(b_node); MathNode *math = new MathNode(); math->type = MathNode::type_enum[b_math_node.operation()]; + math->use_clamp = b_math_node.use_clamp(); node = math; break; } diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index d35c93ccbd2..cb83309cc00 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -47,6 +47,7 @@ BlenderSync::BlenderSync(BL::RenderEngine b_engine_, BL::BlendData b_data_, BL:: object_map(&scene_->objects), mesh_map(&scene_->meshes), light_map(&scene_->lights), + particle_system_map(&scene_->particle_systems), world_map(NULL), world_recalc(false), experimental(false), @@ -97,6 +98,12 @@ bool BlenderSync::sync_recalc() if(b_ob->is_updated_data() || b_ob->data().is_updated()) light_map.set_recalc(*b_ob); } + + if(b_ob->is_updated_data()) { + BL::Object::particle_systems_iterator b_psys; + for (b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) + particle_system_map.set_recalc(*b_ob); + } } BL::BlendData::meshes_iterator b_mesh; @@ -120,6 +127,7 @@ bool BlenderSync::sync_recalc() object_map.has_recalc() || light_map.has_recalc() || mesh_map.has_recalc() || + particle_system_map.has_recalc() || BlendDataObjects_is_updated_get(&b_data.ptr) || world_recalc; @@ -133,6 +141,7 @@ void BlenderSync::sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, const sync_film(); sync_shaders(); sync_objects(b_v3d); + sync_particle_systems(); sync_motion(b_v3d, b_override); } diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index ac1fed060ee..ac4cc37b74a 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -77,6 +77,7 @@ private: void sync_world(); void sync_render_layers(BL::SpaceView3D b_v3d, const char *layer); void sync_shaders(); + void sync_particle_systems(); void sync_nodes(Shader *shader, BL::ShaderNodeTree b_ntree); Mesh *sync_mesh(BL::Object b_ob, bool object_updated); @@ -85,14 +86,14 @@ private: void sync_background_light(); void sync_mesh_motion(BL::Object b_ob, Mesh *mesh, int motion); void sync_camera_motion(BL::Object b_ob, int motion); - void sync_particles(Object *ob, BL::Object b_ob); + void sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys); /* util */ void find_shader(BL::ID id, vector& used_shaders, int default_shader); bool BKE_object_is_modified(BL::Object b_ob); bool object_is_mesh(BL::Object b_ob); bool object_is_light(BL::Object b_ob); - bool object_need_particle_update(BL::Object b_ob); + bool psys_need_update(BL::ParticleSystem b_psys); int object_count_particles(BL::Object b_ob); /* variables */ @@ -104,6 +105,7 @@ private: id_map object_map; id_map mesh_map; id_map light_map; + id_map particle_system_map; set mesh_synced; void *world_map; bool world_recalc; diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index b08c1e7e765..b0febcc23d4 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -149,6 +149,11 @@ static inline float3 get_float3(BL::Array array) return make_float3(array[0], array[1], array[2]); } +static inline float4 get_float4(BL::Array array) +{ + return make_float4(array[0], array[1], array[2], array[3]); +} + static inline int4 get_int4(BL::Array array) { return make_int4(array[0], array[1], array[2], array[3]); @@ -388,6 +393,17 @@ struct ObjectKey { { return (parent < k.parent || (parent == k.parent && (index < k.index || (index == k.index && ob < k.ob)))); } }; +struct ParticleSystemKey { + void *ob; + void *psys; + + ParticleSystemKey(void *ob_, void *psys_) + : ob(ob_), psys(psys_) {} + + bool operator<(const ParticleSystemKey& k) const + { return (ob < k.ob && psys < k.psys); } +}; + CCL_NAMESPACE_END #endif /* __BLENDER_UTIL_H__ */ diff --git a/intern/cycles/cmake/external_libs.cmake b/intern/cycles/cmake/external_libs.cmake index 23a919530f9..4f547a5b644 100644 --- a/intern/cycles/cmake/external_libs.cmake +++ b/intern/cycles/cmake/external_libs.cmake @@ -22,7 +22,7 @@ endif() if(WITH_CYCLES_OSL) - set(CYCLES_OSL "" CACHE PATH "Path to OpenShadingLanguage installation") + set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation") message(STATUS "CYCLES_OSL = ${CYCLES_OSL}") diff --git a/intern/cycles/kernel/kernel_accumulate.h b/intern/cycles/kernel/kernel_accumulate.h index d99beb8905a..e73b2ba70b8 100644 --- a/intern/cycles/kernel/kernel_accumulate.h +++ b/intern/cycles/kernel/kernel_accumulate.h @@ -301,6 +301,10 @@ __device_inline float3 path_radiance_sum(KernelGlobals *kg, PathRadiance *L) __device_inline void path_radiance_clamp(PathRadiance *L, float3 *L_sum, float clamp) { + #ifdef WITH_OSL + using std::isfinite; + #endif + float sum = fabsf((*L_sum).x) + fabsf((*L_sum).y) + fabsf((*L_sum).z); if(!isfinite(sum)) { diff --git a/intern/cycles/kernel/kernel_object.h b/intern/cycles/kernel/kernel_object.h index 4ff315ca265..222ade504cc 100644 --- a/intern/cycles/kernel/kernel_object.h +++ b/intern/cycles/kernel/kernel_object.h @@ -172,24 +172,61 @@ __device int shader_pass_id(KernelGlobals *kg, ShaderData *sd) __device_inline float particle_index(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; - float4 f = kernel_tex_fetch(__particles, offset); + float4 f = kernel_tex_fetch(__particles, offset + 0); return f.x; } __device float particle_age(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; - float4 f = kernel_tex_fetch(__particles, offset); + float4 f = kernel_tex_fetch(__particles, offset + 0); return f.y; } __device float particle_lifetime(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; - float4 f = kernel_tex_fetch(__particles, offset); + float4 f = kernel_tex_fetch(__particles, offset + 0); return f.z; } +__device float particle_size(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset + 0); + return f.w; +} + +__device float4 particle_rotation(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset + 1); + return f; +} + +__device float3 particle_location(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset + 2); + return make_float3(f.x, f.y, f.z); +} + +__device float3 particle_velocity(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f2 = kernel_tex_fetch(__particles, offset + 2); + float4 f3 = kernel_tex_fetch(__particles, offset + 3); + return make_float3(f2.w, f3.x, f3.y); +} + +__device float3 particle_angular_velocity(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f3 = kernel_tex_fetch(__particles, offset + 3); + float4 f4 = kernel_tex_fetch(__particles, offset + 4); + return make_float3(f3.z, f3.w, f4.x); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h index 8d983a4ec75..6c81fa4cfca 100644 --- a/intern/cycles/kernel/kernel_path.h +++ b/intern/cycles/kernel/kernel_path.h @@ -842,15 +842,20 @@ __device float4 kernel_path_non_progressive(KernelGlobals *kg, RNG *rng, int sam path_state_next(kg, &ps, label); /* setup ray */ - ray.P = ray_offset(sd.P, (label & LABEL_TRANSMIT)? -sd.Ng: sd.Ng); - ray.D = bsdf_omega_in; - ray.t = FLT_MAX; + Ray bsdf_ray; + + bsdf_ray.P = ray_offset(sd.P, (label & LABEL_TRANSMIT)? -sd.Ng: sd.Ng); + bsdf_ray.D = bsdf_omega_in; + bsdf_ray.t = FLT_MAX; #ifdef __RAY_DIFFERENTIALS__ - ray.dP = sd.dP; - ray.dD = bsdf_domega_in; + bsdf_ray.dP = sd.dP; + bsdf_ray.dD = bsdf_domega_in; +#endif +#ifdef __MOTION__ + bsdf_ray.time = sd.time; #endif - kernel_path_indirect(kg, rng, sample*num_samples, ray, buffer, + kernel_path_indirect(kg, rng, sample*num_samples, bsdf_ray, buffer, tp*num_samples_inv, min_ray_pdf, bsdf_pdf, ps, rng_offset+PRNG_BOUNCE_NUM, &L); } } diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index bc873f4e112..5ab3c2c2545 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -30,7 +30,7 @@ #include "osl_shader.h" -#else +#endif #include "svm/bsdf.h" #include "svm/emissive.h" @@ -38,7 +38,6 @@ #include "svm/svm_bsdf.h" #include "svm/svm.h" -#endif CCL_NAMESPACE_BEGIN @@ -294,7 +293,8 @@ __device_inline void shader_setup_from_background(KernelGlobals *kg, ShaderData #ifdef __MULTI_CLOSURE__ -__device_inline void _shader_bsdf_multi_eval(const ShaderData *sd, const float3 omega_in, float *pdf, +#ifdef __OSL__ +__device_inline void _shader_bsdf_multi_eval_osl(const ShaderData *sd, const float3 omega_in, float *pdf, int skip_bsdf, BsdfEval *bsdf_eval, float sum_pdf, float sum_sample_weight) { for(int i = 0; i< sd->num_closure; i++) { @@ -305,12 +305,36 @@ __device_inline void _shader_bsdf_multi_eval(const ShaderData *sd, const float3 if(CLOSURE_IS_BSDF(sc->type)) { float bsdf_pdf = 0.0f; -#ifdef __OSL__ + float3 eval = OSLShader::bsdf_eval(sd, sc, omega_in, bsdf_pdf); -#else - float3 eval = svm_bsdf_eval(sd, sc, omega_in, &bsdf_pdf); + + if(bsdf_pdf != 0.0f) { + bsdf_eval_accum(bsdf_eval, sc->type, eval*sc->weight); + sum_pdf += bsdf_pdf*sc->sample_weight; + } + + sum_sample_weight += sc->sample_weight; + } + } + + *pdf = (sum_sample_weight > 0.0f)? sum_pdf/sum_sample_weight: 0.0f; +} #endif +__device_inline void _shader_bsdf_multi_eval_svm(const ShaderData *sd, const float3 omega_in, float *pdf, + int skip_bsdf, BsdfEval *bsdf_eval, float sum_pdf, float sum_sample_weight) +{ + for(int i = 0; i< sd->num_closure; i++) { + if(i == skip_bsdf) + continue; + + const ShaderClosure *sc = &sd->closure[i]; + + if(CLOSURE_IS_BSDF(sc->type)) { + float bsdf_pdf = 0.0f; + + float3 eval = svm_bsdf_eval(sd, sc, omega_in, &bsdf_pdf); + if(bsdf_pdf != 0.0f) { bsdf_eval_accum(bsdf_eval, sc->type, eval*sc->weight); sum_pdf += bsdf_pdf*sc->sample_weight; @@ -331,7 +355,12 @@ __device void shader_bsdf_eval(KernelGlobals *kg, const ShaderData *sd, #ifdef __MULTI_CLOSURE__ bsdf_eval_init(eval, NBUILTIN_CLOSURES, make_float3(0.0f, 0.0f, 0.0f), kernel_data.film.use_light_pass); - return _shader_bsdf_multi_eval(sd, omega_in, pdf, -1, eval, 0.0f, 0.0f); +#ifdef __OSL__ + if (kernel_osl_use(kg)) + return _shader_bsdf_multi_eval_osl(sd, omega_in, pdf, -1, eval, 0.0f, 0.0f); + else +#endif + return _shader_bsdf_multi_eval_svm(sd, omega_in, pdf, -1, eval, 0.0f, 0.0f); #else const ShaderClosure *sc = &sd->closure; @@ -384,16 +413,23 @@ __device int shader_bsdf_sample(KernelGlobals *kg, const ShaderData *sd, *pdf = 0.0f; #ifdef __OSL__ - label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); -#else - label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if (kernel_osl_use(kg)) + label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); + else #endif + label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if(*pdf != 0.0f) { bsdf_eval_init(bsdf_eval, sc->type, eval*sc->weight, kernel_data.film.use_light_pass); if(sd->num_closure > 1) { float sweight = sc->sample_weight; - _shader_bsdf_multi_eval(sd, *omega_in, pdf, sampled, bsdf_eval, *pdf*sweight, sweight); +#ifdef __OSL__ + if (kernel_osl_use(kg)) + _shader_bsdf_multi_eval_osl(sd, *omega_in, pdf, sampled, bsdf_eval, *pdf*sweight, sweight); + else +#endif + _shader_bsdf_multi_eval_svm(sd, *omega_in, pdf, sampled, bsdf_eval, *pdf*sweight, sweight); } } @@ -416,10 +452,12 @@ __device int shader_bsdf_sample_closure(KernelGlobals *kg, const ShaderData *sd, *pdf = 0.0f; #ifdef __OSL__ - label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); -#else - label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if (kernel_osl_use(kg)) + label = OSLShader::bsdf_sample(sd, sc, randu, randv, eval, *omega_in, *domega_in, *pdf); + else #endif + label = svm_bsdf_sample(sd, sc, randu, randv, &eval, omega_in, domega_in, pdf); + if(*pdf != 0.0f) bsdf_eval_init(bsdf_eval, sc->type, eval*sc->weight, kernel_data.film.use_light_pass); @@ -539,10 +577,12 @@ __device float3 shader_emissive_eval(KernelGlobals *kg, ShaderData *sd) if(CLOSURE_IS_EMISSION(sc->type)) { #ifdef __OSL__ - eval += OSLShader::emissive_eval(sd, sc)*sc->weight; -#else - eval += svm_emissive_eval(sd, sc)*sc->weight; + if (kernel_osl_use(kg)) + eval += OSLShader::emissive_eval(sd, sc)*sc->weight; + else #endif + eval += svm_emissive_eval(sd, sc)*sc->weight; + } } #else @@ -581,17 +621,18 @@ __device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { #ifdef __OSL__ - OSLShader::eval_surface(kg, sd, randb, path_flag); -#else - + if (kernel_osl_use(kg)) + OSLShader::eval_surface(kg, sd, randb, path_flag); + else +#endif + { #ifdef __SVM__ - svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, randb, path_flag); + svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, randb, path_flag); #else - bsdf_diffuse_setup(sd, &sd->closure); - sd->closure.weight = make_float3(0.8f, 0.8f, 0.8f); -#endif - + bsdf_diffuse_setup(sd, &sd->closure); + sd->closure.weight = make_float3(0.8f, 0.8f, 0.8f); #endif + } } /* Background Evaluation */ @@ -599,35 +640,37 @@ __device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, __device float3 shader_eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag) { #ifdef __OSL__ - return OSLShader::eval_background(kg, sd, path_flag); -#else + if (kernel_osl_use(kg)) + return OSLShader::eval_background(kg, sd, path_flag); + else +#endif + { #ifdef __SVM__ - svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, 0.0f, path_flag); + svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, 0.0f, path_flag); #ifdef __MULTI_CLOSURE__ - float3 eval = make_float3(0.0f, 0.0f, 0.0f); + float3 eval = make_float3(0.0f, 0.0f, 0.0f); - for(int i = 0; i< sd->num_closure; i++) { - const ShaderClosure *sc = &sd->closure[i]; + for(int i = 0; i< sd->num_closure; i++) { + const ShaderClosure *sc = &sd->closure[i]; - if(CLOSURE_IS_BACKGROUND(sc->type)) - eval += sc->weight; + if(CLOSURE_IS_BACKGROUND(sc->type)) + eval += sc->weight; + } + + return eval; +#else + if(sd->closure.type == CLOSURE_BACKGROUND_ID) + return sd->closure.weight; + else + return make_float3(0.0f, 0.0f, 0.0f); +#endif + +#else + return make_float3(0.8f, 0.8f, 0.8f); +#endif } - - return eval; -#else - if(sd->closure.type == CLOSURE_BACKGROUND_ID) - return sd->closure.weight; - else - return make_float3(0.0f, 0.0f, 0.0f); -#endif - -#else - return make_float3(0.8f, 0.8f, 0.8f); -#endif - -#endif } /* Volume */ @@ -643,10 +686,11 @@ __device float3 shader_volume_eval_phase(KernelGlobals *kg, ShaderData *sd, if(CLOSURE_IS_VOLUME(sc->type)) { #ifdef __OSL__ - eval += OSLShader::volume_eval_phase(sd, sc, omega_in, omega_out); -#else - eval += volume_eval_phase(sd, sc, omega_in, omega_out); + if (kernel_osl_use(kg)) + eval += OSLShader::volume_eval_phase(sd, sc, omega_in, omega_out); + else #endif + eval += volume_eval_phase(sd, sc, omega_in, omega_out); } } @@ -663,10 +707,11 @@ __device void shader_eval_volume(KernelGlobals *kg, ShaderData *sd, { #ifdef __SVM__ #ifdef __OSL__ - OSLShader::eval_volume(kg, sd, randb, path_flag); -#else - svm_eval_nodes(kg, sd, SHADER_TYPE_VOLUME, randb, path_flag); + if (kernel_osl_use(kg)) + OSLShader::eval_volume(kg, sd, randb, path_flag); + else #endif + svm_eval_nodes(kg, sd, SHADER_TYPE_VOLUME, randb, path_flag); #endif } @@ -677,10 +722,11 @@ __device void shader_eval_displacement(KernelGlobals *kg, ShaderData *sd) /* this will modify sd->P */ #ifdef __SVM__ #ifdef __OSL__ - OSLShader::eval_displacement(kg, sd); -#else - svm_eval_nodes(kg, sd, SHADER_TYPE_DISPLACEMENT, 0.0f, 0); + if (kernel_osl_use(kg)) + OSLShader::eval_displacement(kg, sd); + else #endif + svm_eval_nodes(kg, sd, SHADER_TYPE_DISPLACEMENT, 0.0f, 0); #endif } @@ -732,7 +778,8 @@ __device void shader_merge_closures(KernelGlobals *kg, ShaderData *sd) __device void shader_release(KernelGlobals *kg, ShaderData *sd) { #ifdef __OSL__ - OSLShader::release(kg, sd); + if (kernel_osl_use(kg)) + OSLShader::release(kg, sd); #endif } diff --git a/intern/cycles/kernel/kernel_triangle.h b/intern/cycles/kernel/kernel_triangle.h index 6c1ea465515..492800e8aab 100644 --- a/intern/cycles/kernel/kernel_triangle.h +++ b/intern/cycles/kernel/kernel_triangle.h @@ -15,6 +15,8 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "kernel_projection.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 30d45ad1118..39e088583c4 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -33,7 +33,7 @@ CCL_NAMESPACE_BEGIN #define LIGHT_SIZE 4 #define FILTER_TABLE_SIZE 256 #define RAMP_TABLE_SIZE 256 -#define PARTICLE_SIZE 1 +#define PARTICLE_SIZE 5 #define TIME_INVALID FLT_MAX /* device capabilities */ @@ -382,10 +382,9 @@ typedef struct ShaderClosure { #ifdef __OSL__ void *prim; -#else +#endif float data0; float data1; -#endif } ShaderClosure; diff --git a/intern/cycles/kernel/osl/CMakeLists.txt b/intern/cycles/kernel/osl/CMakeLists.txt index 13b2a39d7d0..ce82d901c44 100644 --- a/intern/cycles/kernel/osl/CMakeLists.txt +++ b/intern/cycles/kernel/osl/CMakeLists.txt @@ -42,3 +42,7 @@ include_directories(${INC}) add_library(cycles_kernel_osl ${SRC} ${HEADER_SRC}) add_subdirectory(nodes) + +if(WITH_CYCLES_OSL) + target_link_libraries(cycles_kernel_osl ${OSL_LIBRARIES}) +endif() diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt index 5a645919358..2d2b5b10ce6 100644 --- a/intern/cycles/kernel/osl/nodes/CMakeLists.txt +++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt @@ -8,6 +8,7 @@ set(SRC_OSL node_bump.osl node_camera.osl node_checker_texture.osl + node_combine_rgb.osl node_convert_from_color.osl node_convert_from_float.osl node_convert_from_normal.osl @@ -23,6 +24,7 @@ set(SRC_OSL node_geometry.osl node_glass_bsdf.osl node_glossy_bsdf.osl + node_holdout.osl node_hsv.osl node_image_texture.osl node_invert.osl @@ -34,12 +36,11 @@ set(SRC_OSL node_mix_closure.osl node_musgrave_texture.osl node_normal.osl - node_blend_weight_texture.osl node_noise_texture.osl node_output_displacement.osl node_output_surface.osl node_output_volume.osl - node_sepcomb_rgb.osl + node_separate_rgb.osl node_sky_texture.osl node_texture_coordinate.osl node_translucent_bsdf.osl @@ -57,6 +58,7 @@ set(SRC_OSL_HEADERS node_color.h node_fresnel.h stdosl.h + oslutil.h ) set(SRC_OSO @@ -82,4 +84,5 @@ endforeach() add_custom_target(shader ALL DEPENDS ${SRC_OSO} ${SRC_OSL_HEADERS}) -delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_OSO}" ${CYCLES_INSTALL_PATH}/shader) +# CMAKE_CURRENT_SOURCE_DIR is already included in OSO paths +delayed_install("" "${SRC_OSO}" ${CYCLES_INSTALL_PATH}/shader) diff --git a/intern/cycles/kernel/osl/nodes/node_brightness.osl b/intern/cycles/kernel/osl/nodes/node_brightness.osl index a93ff06d443..4f19a20f736 100644 --- a/intern/cycles/kernel/osl/nodes/node_brightness.osl +++ b/intern/cycles/kernel/osl/nodes/node_brightness.osl @@ -20,15 +20,16 @@ shader node_brightness( color ColorIn = color(0.8, 0.8, 0.8), - float Bright = 0.0, + float Brightness = 0.0, float Contrast = 0.0, - output ColorOut = color(0.8, 0.8, 0.8) + output color ColorOut = color(0.8, 0.8, 0.8)) { float delta = Contrast * (1.0/200.0); float a = 1.0 - delta * 2.0; float b; - Bright *= 1.0/100.0; + /* input value is a percentage */ + float bright_factor = Brightness / 100.0; /* * The algorithm is by Werner D. Streidt @@ -38,11 +39,11 @@ shader node_brightness( if (Contrast > 0.0) { a = (a < 0.0 ? 1.0/a : 0.0); - b = a * (Brightness - delta); + b = a * (bright_factor - delta); } else { delta *= -1.0; - b = a * (Brightness + delta); + b = a * (bright_factor + delta); } ColorOut = a * ColorIn + b; diff --git a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl index 306798b645f..e92d7be34fc 100644 --- a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl @@ -49,10 +49,10 @@ shader node_checker_texture( { Fac = checker(Vector*Scale); if(Fac == 1.0) { - Color = color(Color1, Color1, Color1); + Color = Color1; } else { - Color = color(Color2, Color2, Color2); + Color = Color2; } } diff --git a/intern/cycles/kernel/osl/nodes/node_combine_rgb.osl b/intern/cycles/kernel/osl/nodes/node_combine_rgb.osl new file mode 100644 index 00000000000..546369f660e --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_combine_rgb.osl @@ -0,0 +1,29 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "stdosl.h" + +shader node_combine_rgb( + float R = 0.0, + float G = 0.0, + float B = 0.0, + output color Image = color(0.8, 0.8, 0.8)) +{ + Image = color(R, G, B); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_gamma.osl b/intern/cycles/kernel/osl/nodes/node_gamma.osl index 4dae07d70bc..d55e908b0b7 100644 --- a/intern/cycles/kernel/osl/nodes/node_gamma.osl +++ b/intern/cycles/kernel/osl/nodes/node_gamma.osl @@ -21,13 +21,7 @@ shader node_gamma( color ColorIn = color(0.8, 0.8, 0.8), float Gamma = 1.0, - output ColorOut = color(0.8, 0.8, 0.8) + output color ColorOut = color(0.0, 0.0, 0.0)) { - int i; - for (i=0;i<3;i++) { - if (ColorIn[i] > 0.0) - ColorIn[i] = powf(ColorIn[i], Gamma); - } - - ColorOut = ColorIn; + ColorOut = pow(ColorIn, Gamma); } diff --git a/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl index cc2104af56f..52743669c99 100644 --- a/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl @@ -34,8 +34,8 @@ shader node_glass_bsdf( if(distribution == "Sharp") BSDF = Color*(Fr*reflection(Normal) + (1.0-Fr)*refraction(Normal, eta)); else if(distribution == "Beckmann") - BSDF = Color*(Fr*microfacet_beckmann(Normal, Roughness) + (1.0-Fr)*microfacet_beckmann_refraction(Normal, Roughness, eta)); + BSDF = Color*(Fr*microfacet_beckmann(Normal, Roughness, eta) + (1.0-Fr)*microfacet_beckmann_refraction(Normal, Roughness, eta)); else if(distribution == "GGX") - BSDF = Color*(Fr*microfacet_ggx(Normal, Roughness) + (1.0-Fr)*microfacet_ggx_refraction(Normal, Roughness, eta)); + BSDF = Color*(Fr*microfacet_ggx(Normal, Roughness, eta) + (1.0-Fr)*microfacet_ggx_refraction(Normal, Roughness, eta)); } diff --git a/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl index aa446b66cfb..3890630e8a2 100644 --- a/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl @@ -29,9 +29,9 @@ shader node_glossy_bsdf( if(distribution == "Sharp") BSDF = Color*reflection(Normal); else if(distribution == "Beckmann") - BSDF = Color*microfacet_beckmann(Normal, Roughness); + BSDF = Color*microfacet_beckmann(Normal, Roughness, 1.0); else if(distribution == "GGX") - BSDF = Color*microfacet_ggx(Normal, Roughness); + BSDF = Color*microfacet_ggx(Normal, Roughness, 1.0); } diff --git a/intern/cycles/kernel/osl/nodes/node_invert.osl b/intern/cycles/kernel/osl/nodes/node_invert.osl index 817198c4561..27021942558 100644 --- a/intern/cycles/kernel/osl/nodes/node_invert.osl +++ b/intern/cycles/kernel/osl/nodes/node_invert.osl @@ -21,7 +21,7 @@ shader node_invert( float Fac = 1.0, color ColorIn = color(0.8, 0.8, 0.8), - output ColorOut = color(0.8, 0.8, 0.8) + output color ColorOut = color(0.8, 0.8, 0.8)) { color ColorInv = color(1.0) - ColorIn; ColorOut = mix(ColorIn, ColorInv, Fac); diff --git a/intern/cycles/kernel/osl/nodes/node_math.osl b/intern/cycles/kernel/osl/nodes/node_math.osl index be9bb71d511..3327795286a 100644 --- a/intern/cycles/kernel/osl/nodes/node_math.osl +++ b/intern/cycles/kernel/osl/nodes/node_math.osl @@ -40,6 +40,7 @@ float safe_log(float a, float b) shader node_math( string type = "Add", + int Clamp = 0, float Value1 = 0.0, float Value2 = 0.0, output float Value = 0.0) @@ -80,5 +81,8 @@ shader node_math( Value = Value1 < Value2; if(type == "Greater Than") Value = Value1 > Value2; + + if(Clamp) + Value = clamp(Value1, 0.0, 1.0); } diff --git a/intern/cycles/kernel/osl/nodes/node_mix.osl b/intern/cycles/kernel/osl/nodes/node_mix.osl index 8a462c995d3..661e543fdd8 100644 --- a/intern/cycles/kernel/osl/nodes/node_mix.osl +++ b/intern/cycles/kernel/osl/nodes/node_mix.osl @@ -267,8 +267,20 @@ color node_mix_linear(float t, color col1, color col2) return outcol; } +color node_mix_clamp(color col) +{ + color outcol = col; + + outcol[0] = clamp(col[0], 0.0, 1.0); + outcol[1] = clamp(col[2], 0.0, 1.0); + outcol[2] = clamp(col[2], 0.0, 1.0); + + return outcol; +} + shader node_mix( string type = "Mix", + int Clamp = 0, float Fac = 0.5, color Color1 = color(0.0, 0.0, 0.0), color Color2 = color(0.0, 0.0, 0.0), @@ -312,5 +324,8 @@ shader node_mix( Color = node_mix_soft(t, Color1, Color2); if(type == "Linear Light") Color = node_mix_linear(t, Color1, Color2); + + if(Clamp) + Color = node_mix_clamp(Color); } diff --git a/intern/cycles/kernel/osl/nodes/node_noise_texture.osl b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl index fd9fc1dedc0..7738902f529 100644 --- a/intern/cycles/kernel/osl/nodes/node_noise_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl @@ -27,7 +27,7 @@ float noise(point p, string basis, float distortion, float detail) int hard = 0; float fac = 0.0; - if(distortion != 0.0( { + if(distortion != 0.0) { r[0] = noise_basis(p + point(13.5), basis) * distortion; r[1] = noise_basis(p, basis) * distortion; r[2] = noise_basis(p - point(13.5), basis) * distortion; diff --git a/intern/cycles/kernel/osl/nodes/node_normal.osl b/intern/cycles/kernel/osl/nodes/node_normal.osl index 038a33c9898..d5f16acb88c 100644 --- a/intern/cycles/kernel/osl/nodes/node_normal.osl +++ b/intern/cycles/kernel/osl/nodes/node_normal.osl @@ -22,10 +22,9 @@ shader node_normal( normal Direction = normal(0.0, 0.0, 0.0), normal NormalIn = normal(0.0, 0.0, 0.0), output normal NormalOut = normal(0.0, 0.0, 0.0), - output float Dot = 1.0 + output float Dot = 1.0) { - Direction = normalize(Direction); - NormalOut = Direction; - Dot = dot(Direction, NormalIn); + NormalOut = normalize(Direction); + Dot = dot(NormalOut, NormalIn); } diff --git a/intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl b/intern/cycles/kernel/osl/nodes/node_separate_rgb.osl similarity index 82% rename from intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl rename to intern/cycles/kernel/osl/nodes/node_separate_rgb.osl index a02f31f4b07..b48bd7e59d6 100644 --- a/intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl +++ b/intern/cycles/kernel/osl/nodes/node_separate_rgb.osl @@ -24,17 +24,7 @@ shader node_separate_rgb( output float G = 0.0, output float B = 0.0) { - R = Image[0]; - G = Image[1]; - B = Image[2]; + R = Image[0]; + G = Image[1]; + B = Image[2]; } - -shader node_combine_rgb( - float R = 0.0, - float G = 0.0, - float B = 0.0, - output color Image = color(0.8, 0.8, 0.8) -{ - Image = color(R, G, B) -} - diff --git a/intern/cycles/kernel/osl/nodes/node_texture.h b/intern/cycles/kernel/osl/nodes/node_texture.h index d2dbd6db8b3..b00bf6ab31f 100644 --- a/intern/cycles/kernel/osl/nodes/node_texture.h +++ b/intern/cycles/kernel/osl/nodes/node_texture.h @@ -212,14 +212,17 @@ float noise_wave(string wave, float a) /* Turbulence */ -float noise_turbulence(point p, string basis, int octaves, int hard) +float noise_turbulence(point p, string basis, float details, int hard) { float fscale = 1.0; float amp = 1.0; float sum = 0.0; - int i; + int i, n; + + float octaves = clamp(details, 0.0, 16.0); + n = (int)octaves; - for (i = 0; i <= octaves; i++) { + for (i = 0; i <= n; i++) { float t = noise_basis(fscale * p, basis); if (hard) @@ -229,10 +232,26 @@ float noise_turbulence(point p, string basis, int octaves, int hard) amp *= 0.5; fscale *= 2.0; } + + float rmd = octaves - floor(octaves); - sum *= ((float)(1 << octaves) / (float)((1 << (octaves + 1)) - 1)); + if(rmd != 0.0) { + float t = noise_basis(fscale*p, basis); - return sum; + if(hard) + t = fabs(2.0*t - 1.0); + + float sum2 = sum + t*amp; + + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + sum2 *= ((float)(1 << (n+1))/(float)((1 << (n+2)) - 1)); + + return (1.0 - rmd)*sum + rmd*sum2; + } + else { + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + return sum; + } } /* Utility */ diff --git a/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl index 7a336c148db..5e0cae8cbd1 100644 --- a/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl @@ -27,6 +27,6 @@ shader node_velvet_bsdf( { float sigma = clamp(Sigma, 0.0, 1.0); - BSDF = Color*ashikhmin_velvet(Normal, sigma); + BSDF = Color*ashikhmin_velvet(Normal, sigma, 1.0); } diff --git a/intern/cycles/kernel/osl/nodes/node_wave_texture.osl b/intern/cycles/kernel/osl/nodes/node_wave_texture.osl index b55ec771be8..693f09ae24c 100644 --- a/intern/cycles/kernel/osl/nodes/node_wave_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_wave_texture.osl @@ -31,14 +31,14 @@ float wave(point p, float scale, string type, float detail, float distortion, fl float n = 0.0; if(type == "Bands") { - n = (x + y + z)*10.0); + n = (x + y + z)*10.0; } else if(type == "Rings") { n = (sqrt(x*x + y*y + z*z)*20.0); } if(distortion != 0.0) { - n = n +(distortion * noise_turbulence(p*dscale, "Perlin", detail, 0); + n = n +(distortion * noise_turbulence(p*dscale, "Perlin", detail, 0)); } result = noise_wave("Sine", n); diff --git a/intern/cycles/kernel/osl/nodes/oslutil.h b/intern/cycles/kernel/osl/nodes/oslutil.h new file mode 100644 index 00000000000..08611187a3c --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/oslutil.h @@ -0,0 +1,91 @@ +///////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of Sony Pictures Imageworks nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +///////////////////////////////////////////////////////////////////////////// + + +#ifndef CCL_OSLUTIL_H +#define CCL_OSLUTIL_H + +// Return wireframe opacity factor [0, 1] given a geometry type in +// ("triangles", "polygons" or "patches"), and a line_width in raster +// or world space depending on the last (raster) boolean argument. +// +float wireframe(string edge_type, float line_width, int raster) +{ + // ray differentials are so big in diffuse context that this function would always return "wire" + if (raytype("path:diffuse")) return 0.0; + + int np = 0; + point p[64]; + float pixelWidth = 1; + + if (edge_type == "triangles") + { + np = 3; + if (!getattribute("geom:trianglevertices", p)) + return 0.0; + } + else if (edge_type == "polygons" || edge_type == "patches") + { + getattribute("geom:numpolyvertices", np); + if (np < 3 || !getattribute("geom:polyvertices", p)) + return 0.0; + } + + if (raster) + { + // Project the derivatives of P to the viewing plane defined + // by I so we have a measure of how big is a pixel at this point + float pixelWidthX = length(Dx(P) - dot(Dx(P), I) * I); + float pixelWidthY = length(Dy(P) - dot(Dy(P), I) * I); + // Take the average of both axis' length + pixelWidth = (pixelWidthX + pixelWidthY) / 2; + } + + // Use half the width as the neighbor face will render the + // other half. And take the square for fast comparison + pixelWidth *= 0.5 * line_width; + pixelWidth *= pixelWidth; + for (int i = 0; i < np; i++) + { + int i2 = i ? i - 1 : np - 1; + vector dir = P - p[i]; + vector edge = p[i] - p[i2]; + vector crs = cross(edge, dir); + // At this point dot(crs, crs) / dot(edge, edge) is + // the square of area / length(edge) == square of the + // distance to the edge. + if (dot(crs, crs) < (dot(edge, edge) * pixelWidth)) + return 1; + } + return 0; +} + +float wireframe(string edge_type, float line_width) { return wireframe(edge_type, line_width, 1); } +float wireframe(string edge_type) { return wireframe(edge_type, 1.0, 1); } +float wireframe() { return wireframe("polygons", 1.0, 1); } + +#endif /* CCL_OSLUTIL_H */ diff --git a/intern/cycles/kernel/osl/nodes/stdosl.h b/intern/cycles/kernel/osl/nodes/stdosl.h index 0c07c501d69..e5accf4eb54 100644 --- a/intern/cycles/kernel/osl/nodes/stdosl.h +++ b/intern/cycles/kernel/osl/nodes/stdosl.h @@ -35,6 +35,8 @@ #define M_PI_2 1.5707963267948966 /* pi/2 */ #define M_PI_4 0.7853981633974483 /* pi/4 */ #define M_2_PI 0.6366197723675813 /* 2/pi */ +#define M_2PI 6.2831853071795865 /* 2*pi */ +#define M_4PI 12.566370614359173 /* 4*pi */ #define M_2_SQRTPI 1.1283791670955126 /* 2/sqrt(pi) */ #define M_E 2.7182818284590452 /* e (Euler's number) */ #define M_LN2 0.6931471805599453 /* ln(2) */ @@ -121,9 +123,16 @@ PERCOMP1 (round) PERCOMP1 (trunc) PERCOMP2 (fmod) PERCOMP2F (fmod) -PERCOMP2 (mod) -PERCOMP2F (mod) -int mod (int x, int y) BUILTIN; +int mod (int a, int b) { return a - b*(int)floor(a/b); } +point mod (point a, point b) { return a - b*floor(a/b); } +vector mod (vector a, vector b) { return a - b*floor(a/b); } +normal mod (normal a, normal b) { return a - b*floor(a/b); } +color mod (color a, color b) { return a - b*floor(a/b); } +point mod (point a, float b) { return a - b*floor(a/b); } +vector mod (vector a, float b) { return a - b*floor(a/b); } +normal mod (normal a, float b) { return a - b*floor(a/b); } +color mod (color a, float b) { return a - b*floor(a/b); } +float mod (float a, float b) { return a - b*floor(a/b); } PERCOMP2 (min) PERCOMP2 (max) normal clamp (normal x, normal minval, normal maxval) { return max(min(x,maxval),minval); } @@ -131,11 +140,6 @@ vector clamp (vector x, vector minval, vector maxval) { return max(min(x,maxval) point clamp (point x, point minval, point maxval) { return max(min(x,maxval),minval); } color clamp (color x, color minval, color maxval) { return max(min(x,maxval),minval); } float clamp (float x, float minval, float maxval) { return max(min(x,maxval),minval); } -//normal clamp (normal x, normal minval, normal maxval) BUILTIN; -//vector clamp (vector x, vector minval, vector maxval) BUILTIN; -//point clamp (point x, point minval, point maxval) BUILTIN; -//color clamp (color x, color minval, color maxval) BUILTIN; -//float clamp (float x, float minval, float maxval) BUILTIN; normal mix (normal x, normal y, normal a) { return x*(1-a) + y*a; } normal mix (normal x, normal y, float a) { return x*(1-a) + y*a; } vector mix (vector x, vector y, vector a) { return x*(1-a) + y*a; } @@ -163,246 +167,234 @@ vector normalize (vector v) BUILTIN; vector faceforward (vector N, vector I, vector Nref) BUILTIN; vector faceforward (vector N, vector I) BUILTIN; vector reflect (vector I, vector N) { return I - 2*dot(N,I)*N; } -vector refract(vector I, vector N, float eta) { - float IdotN = dot(I, N); - float k = 1 - eta * eta * (1 - IdotN * IdotN); - return (k < 0) ? vector(0, 0, 0) : (eta * I - N * (eta * IdotN + sqrt(k))); +vector refract (vector I, vector N, float eta) { + float IdotN = dot (I, N); + float k = 1 - eta*eta * (1 - IdotN*IdotN); + return (k < 0) ? vector(0,0,0) : (eta*I - N * (eta*IdotN + sqrt(k))); } -void fresnel(vector I, normal N, float eta, - output float Kr, output float Kt, - output vector R, output vector T) +void fresnel (vector I, normal N, float eta, + output float Kr, output float Kt, + output vector R, output vector T) { - float sqr(float x) { - return x * x; - } - float c = dot(I, N); - if (c < 0) - c = -c; - R = reflect(I, N); - float g = 1.0 / sqr(eta) - 1.0 + c * c; - if (g >= 0.0) { - g = sqrt(g); - float beta = g - c; - float F = (c * (g + c) - 1.0) / (c * beta + 1.0); - F = 0.5 * (1.0 + sqr(F)); - F *= sqr(beta / (g + c)); - Kr = F; - Kt = (1.0 - Kr) * eta * eta; - // OPT: the following recomputes some of the above values, but it - // gives us the same result as if the shader-writer called refract() - T = refract(I, N, eta); - } - else { - // total internal reflection - Kr = 1.0; - Kt = 0.0; - T = vector(0, 0, 0); - } -#undef sqr + float sqr(float x) { return x*x; } + float c = dot(I, N); + if (c < 0) + c = -c; + R = reflect(I, N); + float g = 1.0 / sqr(eta) - 1.0 + c * c; + if (g >= 0.0) { + g = sqrt (g); + float beta = g - c; + float F = (c * (g+c) - 1.0) / (c * beta + 1.0); + F = 0.5 * (1.0 + sqr(F)); + F *= sqr (beta / (g+c)); + Kr = F; + Kt = (1.0 - Kr) * eta*eta; + // OPT: the following recomputes some of the above values, but it + // gives us the same result as if the shader-writer called refract() + T = refract(I, N, eta); + } else { + // total internal reflection + Kr = 1.0; + Kt = 0.0; + T = vector (0,0,0); + } } -void fresnel(vector I, normal N, float eta, - output float Kr, output float Kt) +void fresnel (vector I, normal N, float eta, + output float Kr, output float Kt) { - vector R, T; - fresnel(I, N, eta, Kr, Kt, R, T); + vector R, T; + fresnel(I, N, eta, Kr, Kt, R, T); } -point rotate(point q, float angle, point a, point b) BUILTIN; -normal transform(matrix Mto, normal p) BUILTIN; -vector transform(matrix Mto, vector p) BUILTIN; -point transform(matrix Mto, point p) BUILTIN; +normal transform (matrix Mto, normal p) BUILTIN; +vector transform (matrix Mto, vector p) BUILTIN; +point transform (matrix Mto, point p) BUILTIN; +normal transform (string from, string to, normal p) BUILTIN; +vector transform (string from, string to, vector p) BUILTIN; +point transform (string from, string to, point p) BUILTIN; +normal transform (string to, normal p) { return transform("common",to,p); } +vector transform (string to, vector p) { return transform("common",to,p); } +point transform (string to, point p) { return transform("common",to,p); } -// Implementation of transform-with-named-space in terms of matrices: +float transformu (string tounits, float x) BUILTIN; +float transformu (string fromunits, string tounits, float x) BUILTIN; -point transform(string tospace, point x) +point rotate (point p, float angle, point a, point b) { - return transform(matrix("common", tospace), x); + vector axis = normalize (b - a); + float cosang, sinang; + sincos (angle, sinang, cosang); + float cosang1 = 1.0 - cosang; + float x = axis[0], y = axis[1], z = axis[2]; + matrix M = matrix (x * x + (1.0 - x * x) * cosang, + x * y * cosang1 + z * sinang, + x * z * cosang1 - y * sinang, + 0.0, + x * y * cosang1 - z * sinang, + y * y + (1.0 - y * y) * cosang, + y * z * cosang1 + x * sinang, + 0.0, + x * z * cosang1 + y * sinang, + y * z * cosang1 - x * sinang, + z * z + (1.0 - z * z) * cosang, + 0.0, + 0.0, 0.0, 0.0, 1.0); + return transform (M, p-a) + a; } -point transform(string fromspace, string tospace, point x) -{ - return transform(matrix(fromspace, tospace), x); -} - - -vector transform(string tospace, vector x) -{ - return transform(matrix("common", tospace), x); -} - -vector transform(string fromspace, string tospace, vector x) -{ - return transform(matrix(fromspace, tospace), x); -} - - -normal transform(string tospace, normal x) -{ - return transform(matrix("common", tospace), x); -} - -normal transform(string fromspace, string tospace, normal x) -{ - return transform(matrix(fromspace, tospace), x); -} - -float transformu(string tounits, float x) BUILTIN; -float transformu(string fromunits, string tounits, float x) BUILTIN; // Color functions -float luminance(color c) { - return dot((vector)c, vector(0.2126, 0.7152, 0.0722)); +float luminance (color c) BUILTIN; +color blackbody (float temperatureK) BUILTIN; +color wavelength_color (float wavelength_nm) BUILTIN; + + +color transformc (string to, color x) +{ + color rgb_to_hsv (color rgb) { // See Foley & van Dam + float r = rgb[0], g = rgb[1], b = rgb[2]; + float mincomp = min (r, min (g, b)); + float maxcomp = max (r, max (g, b)); + float delta = maxcomp - mincomp; // chroma + float h, s, v; + v = maxcomp; + if (maxcomp > 0) + s = delta / maxcomp; + else s = 0; + if (s <= 0) + h = 0; + else { + if (r >= maxcomp) h = (g-b) / delta; + else if (g >= maxcomp) h = 2 + (b-r) / delta; + else h = 4 + (r-g) / delta; + h /= 6; + if (h < 0) + h += 1; + } + return color (h, s, v); + } + + color rgb_to_hsl (color rgb) { // See Foley & van Dam + // First convert rgb to hsv, then to hsl + float minval = min (rgb[0], min (rgb[1], rgb[2])); + color hsv = rgb_to_hsv (rgb); + float maxval = hsv[2]; // v == maxval + float h = hsv[0], s, l = (minval+maxval) / 2; + if (minval == maxval) + s = 0; // special 'achromatic' case, hue is 0 + else if (l <= 0.5) + s = (maxval - minval) / (maxval + minval); + else + s = (maxval - minval) / (2 - maxval - minval); + return color (h, s, l); + } + + color r; + if (to == "rgb" || to == "RGB") + r = x; + else if (to == "hsv") + r = rgb_to_hsv (x); + else if (to == "hsl") + r = rgb_to_hsl (x); + else if (to == "YIQ") + r = color (dot (vector(0.299, 0.587, 0.114), (vector)x), + dot (vector(0.596, -0.275, -0.321), (vector)x), + dot (vector(0.212, -0.523, 0.311), (vector)x)); + else if (to == "xyz") + r = color (dot (vector(0.412453, 0.357580, 0.180423), (vector)x), + dot (vector(0.212671, 0.715160, 0.072169), (vector)x), + dot (vector(0.019334, 0.119193, 0.950227), (vector)x)); + else { + error ("Unknown color space \"%s\"", to); + r = x; + } + return r; } - -color transformc(string to, color x) +color transformc (string from, string to, color x) { - color rgb_to_hsv(color rgb) { // See Foley & van Dam - float r = rgb[0], g = rgb[1], b = rgb[2]; - float mincomp = min(r, min(g, b)); - float maxcomp = max(r, max(g, b)); - float delta = maxcomp - mincomp; // chroma - float h, s, v; - v = maxcomp; - if (maxcomp > 0) - s = delta / maxcomp; - else s = 0; - if (s <= 0) - h = 0; - else { - if (r >= maxcomp) h = (g - b) / delta; - else if (g >= maxcomp) h = 2 + (b - r) / delta; - else h = 4 + (r - g) / delta; - h /= 6; - if (h < 0) - h += 1; - } - return color(h, s, v); - } + color hsv_to_rgb (color c) { // Reference: Foley & van Dam + float h = c[0], s = c[1], v = c[2]; + color r; + if (s < 0.0001) { + r = v; + } else { + h = 6 * (h - floor(h)); // expand to [0..6) + int hi = (int)h; + float f = h - hi; + float p = v * (1-s); + float q = v * (1-s*f); + float t = v * (1-s*(1-f)); + if (hi == 0) r = color (v, t, p); + else if (hi == 1) r = color (q, v, p); + else if (hi == 2) r = color (p, v, t); + else if (hi == 3) r = color (p, q, v); + else if (hi == 4) r = color (t, p, v); + else r = color (v, p, q); + } + return r; + } - color rgb_to_hsl(color rgb) { // See Foley & van Dam - // First convert rgb to hsv, then to hsl - float minval = min(rgb[0], min(rgb[1], rgb[2])); - color hsv = rgb_to_hsv(rgb); - float maxval = hsv[2]; // v == maxval - float h = hsv[0], s, l = (minval + maxval) / 2; - if (minval == maxval) - s = 0; // special 'achromatic' case, hue is 0 - else if (l <= 0.5) - s = (maxval - minval) / (maxval + minval); - else - s = (maxval - minval) / (2 - maxval - minval); - return color(h, s, l); - } + color hsl_to_rgb (color c) { + float h = c[0], s = c[1], l = c[2]; + // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam) + float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s); + color r; + if (v <= 0) { + r = 0; + } else { + float min = 2 * l - v; + s = (v - min) / v; + r = hsv_to_rgb (color (h, s, v)); + } + return r; + } - color r; - if (to == "rgb" || to == "RGB") - r = x; - else if (to == "hsv") - r = rgb_to_hsv(x); - else if (to == "hsl") - r = rgb_to_hsl(x); - else if (to == "YIQ") - r = color(dot(vector(0.299, 0.587, 0.114), (vector)x), - dot(vector(0.596, -0.275, -0.321), (vector)x), - dot(vector(0.212, -0.523, 0.311), (vector)x)); - else if (to == "xyz") - r = color(dot(vector(0.412453, 0.357580, 0.180423), (vector)x), - dot(vector(0.212671, 0.715160, 0.072169), (vector)x), - dot(vector(0.019334, 0.119193, 0.950227), (vector)x)); - else { - error("Unknown color space \"%s\"", to); - r = x; - } - return r; -} - - -color transformc(string from, string to, color x) -{ - color hsv_to_rgb(color c) { // Reference: Foley & van Dam - float h = c[0], s = c[1], v = c[2]; - color r; - if (s < 0.0001) { - r = v; - } - else { - h = 6 * (h - floor(h)); // expand to [0..6) - int hi = (int)h; - float f = h - hi; - float p = v * (1 - s); - float q = v * (1 - s * f); - float t = v * (1 - s * (1 - f)); - if (hi == 0) r = color(v, t, p); - else if (hi == 1) r = color(q, v, p); - else if (hi == 2) r = color(p, v, t); - else if (hi == 3) r = color(p, q, v); - else if (hi == 4) r = color(t, p, v); - else r = color(v, p, q); - } - return r; - } - - color hsl_to_rgb(color c) { - float h = c[0], s = c[1], l = c[2]; - // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam) - float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s); - color r; - if (v <= 0) { - r = 0; - } - else { - float min = 2 * l - v; - s = (v - min) / v; - r = hsv_to_rgb(color(h, s, v)); - } - return r; - } - - color r; - if (from == "rgb" || from == "RGB") - r = x; - else if (from == "hsv") - r = hsv_to_rgb(x); - else if (from == "hsl") - r = hsl_to_rgb(x); - else if (from == "YIQ") - r = color(dot(vector(1, 0.9557, 0.6199), (vector)x), - dot(vector(1, -0.2716, -0.6469), (vector)x), - dot(vector(1, -1.1082, 1.7051), (vector)x)); - else if (from == "xyz") - r = color(dot(vector(3.240479, -1.537150, -0.498535), (vector)x), - dot(vector(-0.969256, 1.875991, 0.041556), (vector)x), - dot(vector(0.055648, -0.204043, 1.057311), (vector)x)); - else { - error("Unknown color space \"%s\"", to); - r = x; - } - return transformc(to, r); + color r; + if (from == "rgb" || from == "RGB") + r = x; + else if (from == "hsv") + r = hsv_to_rgb (x); + else if (from == "hsl") + r = hsl_to_rgb (x); + else if (from == "YIQ") + r = color (dot (vector(1, 0.9557, 0.6199), (vector)x), + dot (vector(1, -0.2716, -0.6469), (vector)x), + dot (vector(1, -1.1082, 1.7051), (vector)x)); + else if (from == "xyz") + r = color (dot (vector( 3.240479, -1.537150, -0.498535), (vector)x), + dot (vector(-0.969256, 1.875991, 0.041556), (vector)x), + dot (vector( 0.055648, -0.204043, 1.057311), (vector)x)); + else { + error ("Unknown color space \"%s\"", to); + r = x; + } + return transformc (to, r); } // Matrix functions -float determinant(matrix m) BUILTIN; -matrix transpose(matrix m) BUILTIN; +float determinant (matrix m) BUILTIN; +matrix transpose (matrix m) BUILTIN; // Pattern generation -float step(float edge, float x) BUILTIN; -color step(color edge, color x) BUILTIN; -point step(point edge, point x) BUILTIN; -vector step(vector edge, vector x) BUILTIN; -normal step(normal edge, normal x) BUILTIN; -float smoothstep(float edge0, float edge1, float x) BUILTIN; +float step (float edge, float x) BUILTIN; +color step (color edge, color x) BUILTIN; +point step (point edge, point x) BUILTIN; +vector step (vector edge, vector x) BUILTIN; +normal step (normal edge, normal x) BUILTIN; +float smoothstep (float edge0, float edge1, float x) BUILTIN; // Derivatives and area operators @@ -413,26 +405,24 @@ float smoothstep(float edge0, float edge1, float x) BUILTIN; // String functions -int strlen(string s) BUILTIN; -int startswith(string s, string prefix) BUILTIN; -int endswith(string s, string suffix) BUILTIN; -string substr(string s, int start, int len) BUILTIN; -string substr(string s, int start) { - return substr(s, start, strlen(s)); -} +int strlen (string s) BUILTIN; +int startswith (string s, string prefix) BUILTIN; +int endswith (string s, string suffix) BUILTIN; +string substr (string s, int start, int len) BUILTIN; +string substr (string s, int start) { return substr (s, start, strlen(s)); } // Define concat in terms of shorter concat -string concat(string a, string b, string c) { - return concat(concat(a, b), c); +string concat (string a, string b, string c) { + return concat(concat(a,b), c); } -string concat(string a, string b, string c, string d) { - return concat(concat(a, b, c), d); +string concat (string a, string b, string c, string d) { + return concat(concat(a,b,c), d); } -string concat(string a, string b, string c, string d, string e) { - return concat(concat(a, b, c, d), e); +string concat (string a, string b, string c, string d, string e) { + return concat(concat(a,b,c,d), e); } -string concat(string a, string b, string c, string d, string e, string f) { - return concat(concat(a, b, c, d, e), f); +string concat (string a, string b, string c, string d, string e, string f) { + return concat(concat(a,b,c,d,e), f); } @@ -445,16 +435,20 @@ closure color diffuse(normal N) BUILTIN; closure color oren_nayar(normal N, float sigma) BUILTIN; closure color translucent(normal N) BUILTIN; closure color reflection(normal N, float eta) BUILTIN; -closure color reflection(normal N) { return reflection(N, 0.0); } +closure color reflection(normal N) { return reflection (N, 0.0); } closure color refraction(normal N, float eta) BUILTIN; closure color dielectric(normal N, float eta) BUILTIN; closure color transparent() BUILTIN; -closure color microfacet_ggx(normal N, float ag) BUILTIN; +closure color microfacet_ggx(normal N, float ag, float eta) BUILTIN; closure color microfacet_ggx_refraction(normal N, float ag, float eta) BUILTIN; -closure color microfacet_beckmann(normal N, float ab) BUILTIN; +closure color microfacet_beckmann(normal N, float ab, float eta) BUILTIN; closure color microfacet_beckmann_refraction(normal N, float ab, float eta) BUILTIN; -closure color ward(normal N, vector T, float ax, float ay) BUILTIN; -closure color ashikhmin_velvet(normal N, float sigma) BUILTIN; +closure color ward(normal N, vector T,float ax, float ay) BUILTIN; +closure color phong(normal N, float exponent) BUILTIN; +closure color phong_ramp(normal N, float exponent, color colors[8]) BUILTIN; +closure color hair_diffuse(vector T) BUILTIN; +closure color hair_specular(vector T, float offset, float exponent) BUILTIN; +closure color ashikhmin_velvet(normal N, float sigma, float eta) BUILTIN; closure color westin_backscatter(normal N, float roughness) BUILTIN; closure color westin_sheen(normal N, float edginess) BUILTIN; closure color bssrdf_cubic(color radius) BUILTIN; @@ -464,10 +458,75 @@ closure color emission() BUILTIN; closure color debug(string tag) BUILTIN; closure color background() BUILTIN; closure color holdout() BUILTIN; -closure color subsurface(float eta, float g, float mfp, float albedo) BUILTIN; +closure color subsurface(float eta, float g, color mfp, color albedo) BUILTIN; + +closure color cloth(normal N, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, + float area_scaled, vector dPdu, color diff_warp_col, color diff_weft_col, + color spec_warp_col, color spec_weft_col, float fresnel_warp, float fresnel_weft, + float spread_x_mult, float spread_y_mult, int pattern, float pattern_angle, + float warp_width_scale, float weft_width_scale, float thread_count_mult_u, + float thread_count_mult_v) BUILTIN; +closure color cloth_specular(normal N, color spec_col[4], float eta[4], int thread_pattern[4], + float pattern_weight[4], int current_thread, float brdf_interp, + float btf_interp, float uux, float vvx, float area_scaled, vector dPdu, + float eccentricity[4], float angle[4], float Kx[4], float Ky[4], + float Sx[4], float Sy[4]) BUILTIN; +closure color fakefur_diffuse(normal N, vector T, float fur_reflectivity, float fur_transmission, + float shadow_start, float shadow_end, float fur_attenuation, float fur_density, + float fur_avg_radius, float fur_length, float fur_shadow_fraction) BUILTIN; +closure color fakefur_specular(normal N, vector T, float offset, float exp, float fur_reflectivity, + float fur_transmission, float shadow_start, float shadow_end, + float fur_attenuation, float fur_density, float fur_avg_radius, + float fur_length, float fur_shadow_fraction) BUILTIN; + +closure color fakefur_skin(vector N, vector T, float fur_reflectivity, float fur_transmission, + float shadow_start, float shadow_end, float fur_attenuation, float fur_density, + float fur_avg_radius, float fur_length) BUILTIN; + + +closure color cloth(normal N, float s, float t, color diff_warp, color diff_weft, + color spec_warp, color spec_weft, float fresnel_warp, float fresnel_weft, + float spread_x_mult, float spread_y_mult, int pattern, float pattern_angle, + float warp_width_scale, float weft_width_scale, float thread_count_mult_u, + float thread_count_mult_v) +{ + + return cloth(N, s, t, Dx(s), Dx(t), Dy(s), Dy(t), area(P), dPdu, diff_warp, diff_weft, spec_warp, spec_weft, + fresnel_warp, fresnel_weft, spread_x_mult, spread_y_mult, pattern, pattern_angle, + warp_width_scale, weft_width_scale, thread_count_mult_u, thread_count_mult_v); +} + +closure color cloth(normal N, float s, float t, color diff_warp, color diff_weft, + color spec_warp, color spec_weft, float fresnel_warp, float fresnel_weft, + float spread_x_mult, float spread_y_mult, int pattern, float pattern_angle, + float warp_width_scale, float weft_width_scale, float thread_count_mult_u, + float thread_count_mult_v, string tok, string val) +{ + + return cloth(N, s, t, Dx(s), Dx(t), Dy(s), Dy(t), area(P), dPdu, diff_warp, diff_weft, spec_warp, spec_weft, + fresnel_warp, fresnel_weft, spread_x_mult, spread_y_mult, pattern, pattern_angle, + warp_width_scale, weft_width_scale, thread_count_mult_u, thread_count_mult_v, tok, val); +} + + // Renderer state -int raytype(string typename) BUILTIN; +int raytype (string typename) BUILTIN; +// the individual 'isFOOray' functions are deprecated +int iscameraray () { return raytype("camera"); } +int isdiffuseray () { return raytype("diffuse"); } +int isglossyray () { return raytype("glossy"); } +int isshadowray () { return raytype("shadow"); } +int getmatrix (string fromspace, string tospace, output matrix M) BUILTIN; +int getmatrix (string fromspace, output matrix M) { + return getmatrix (fromspace, "common", M); +} + + +// Miscellaneous + + + #undef BUILTIN #undef BUILTIN_DERIV @@ -476,4 +535,3 @@ int raytype(string typename) BUILTIN; #undef PERCOMP2F #endif /* CCL_STDOSL_H */ - diff --git a/intern/cycles/kernel/osl/osl_globals.h b/intern/cycles/kernel/osl/osl_globals.h index 90746c385c7..075c68824e6 100644 --- a/intern/cycles/kernel/osl/osl_globals.h +++ b/intern/cycles/kernel/osl/osl_globals.h @@ -30,12 +30,15 @@ CCL_NAMESPACE_BEGIN +class OSLRenderServices; + struct OSLGlobals { /* use */ bool use; /* shading system */ OSL::ShadingSystem *ss; + OSLRenderServices *services; /* shader states */ vector surface_state; @@ -60,7 +63,7 @@ struct OSLGlobals { /* thread key for thread specific data lookup */ struct ThreadData { OSL::ShaderGlobals globals; - void *thread_info; + OSL::PerThreadInfo *thread_info; }; static tls_ptr(ThreadData, thread_data); diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index a1574d6e0db..a3f2c2ea369 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -160,6 +160,18 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl return false; } +bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform) +{ + // XXX implementation + return true; +} + +bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, ustring from) +{ + // XXX implementation + return true; +} + bool OSLRenderServices::get_array_attribute(void *renderstate, bool derivatives, ustring object, TypeDesc type, ustring name, int index, void *val) @@ -297,137 +309,16 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, void *renderst return false; /* never called by OSL */ } -void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names, - TypeDesc *attr_types, int nattrs) +int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 ¢er, + float radius, int max_points, bool sort, size_t *out_indices, float *out_distances, int derivs_offset) { -#ifdef WITH_PARTIO - m_attr_queries.push_back(AttrQuery()); - AttrQuery &query = m_attr_queries.back(); - - /* make space for what we need. the only reason to use - * std::vector is to skip the delete */ - query.attr_names.resize(nattrs); - query.attr_partio_types.resize(nattrs); - /* capacity will keep the length of the smallest array passed - * to the query. Just to prevent buffer overruns */ - query.capacity = -1; - - for (int i = 0; i < nattrs; ++i) { - query.attr_names[i] = attr_names[i]; - - TypeDesc element_type = attr_types[i].elementtype(); - - if (query.capacity < 0) - query.capacity = attr_types[i].numelements(); - else - query.capacity = min(query.capacity, (int)attr_types[i].numelements()); - - /* convert the OSL (OIIO) type to the equivalent Partio type so - * we can do a fast check at query time. */ - if (element_type == TypeDesc::TypeFloat) { - query.attr_partio_types[i] = Partio::FLOAT; - } - else if (element_type == TypeDesc::TypeInt) { - query.attr_partio_types[i] = Partio::INT; - } - else if (element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint || - element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal) - { - query.attr_partio_types[i] = Partio::VECTOR; - } - else { - return NULL; /* report some error of unknown type */ - } - } - - /* this is valid until the end of RenderServices */ - return &query; -#else - return NULL; -#endif + return 0; } -#ifdef WITH_PARTIO -Partio::ParticlesData *OSLRenderServices::get_pointcloud(ustring filename) +int OSLRenderServices::pointcloud_get(ustring filename, size_t *indices, int count, + ustring attr_name, TypeDesc attr_type, void *out_data) { - return Partio::readCached(filename.c_str(), true); -} - -#endif - -int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, float radius, - int max_points, void *_attr_query, void **attr_outdata) -{ - /* todo: this code has never been tested, and most likely does not - * work. it's based on the example code in OSL */ - -#ifdef WITH_PARTIO - /* query Partio for this pointcloud lookup using cached attr_query */ - if (!_attr_query) - return 0; - - AttrQuery *attr_query = (AttrQuery *)_attr_query; - if (attr_query->capacity < max_points) - return 0; - - /* get the pointcloud entry for the given filename */ - Partio::ParticlesData *cloud = get_pointcloud(filename); - - /* now we have to look up all the attributes in the file. we can't do this - * before hand cause we never know what we are going to load. */ - int nattrs = attr_query->attr_names.size(); - Partio::ParticleAttribute *attr = (Partio::ParticleAttribute *)alloca(sizeof(Partio::ParticleAttribute) * nattrs); - - for (int i = 0; i < nattrs; ++i) { - /* special case attributes */ - if (attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index) - continue; - - /* lookup the attribute by name*/ - if (!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) { - /* issue an error here and return, types don't match */ - Partio::endCachedAccess(cloud); - cloud->release(); - return 0; - } - } - - std::vector indices; - std::vector dist2; - - Partio::beginCachedAccess(cloud); - - /* finally, do the lookup */ - cloud->findNPoints((const float *)¢er, max_points, radius, indices, dist2); - int count = indices.size(); - - /* retrieve the attributes directly to user space */ - for (int j = 0; j < nattrs; ++j) { - /* special cases */ - if (attr_query->attr_names[j] == u_distance) { - for (int i = 0; i < count; ++i) - ((float *)attr_outdata[j])[i] = sqrtf(dist2[i]); - } - else if (attr_query->attr_names[j] == u_index) { - for (int i = 0; i < count; ++i) - ((int *)attr_outdata[j])[i] = indices[i]; - } - else { - /* note we make a single call per attribute, we don't loop over the - * points. Partio does it, so it is there that we have to care about - * performance */ - cloud->data(attr[j], count, &indices[0], true, attr_outdata[j]); - } - } - - Partio::endCachedAccess(cloud); - cloud->release(); - - return count; -#else - return 0; -#endif + return 0; } CCL_NAMESPACE_END - diff --git a/intern/cycles/kernel/osl/osl_services.h b/intern/cycles/kernel/osl/osl_services.h index e637b53ab78..60ff463f033 100644 --- a/intern/cycles/kernel/osl/osl_services.h +++ b/intern/cycles/kernel/osl/osl_services.h @@ -30,10 +30,6 @@ #include #include -#ifdef WITH_PARTIO -#include -#endif - CCL_NAMESPACE_BEGIN class Object; @@ -53,8 +49,12 @@ public: bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time); bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time); + bool get_matrix(OSL::Matrix44 &result, ustring from, float time); bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time); + + bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform); + bool get_matrix(OSL::Matrix44 &result, ustring from); bool get_array_attribute(void *renderstate, bool derivatives, ustring object, TypeDesc type, ustring name, @@ -65,36 +65,17 @@ public: bool get_userdata(bool derivatives, ustring name, TypeDesc type, void *renderstate, void *val); bool has_userdata(ustring name, TypeDesc type, void *renderstate); + + int pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 ¢er, + float radius, int max_points, bool sort, size_t *out_indices, + float *out_distances, int derivs_offset); - void *get_pointcloud_attr_query(ustring *attr_names, - TypeDesc *attr_types, int nattrs); - int pointcloud(ustring filename, const OSL::Vec3 ¢er, float radius, - int max_points, void *attr_query, void **attr_outdata); + int pointcloud_get(ustring filename, size_t *indices, int count, ustring attr_name, + TypeDesc attr_type, void *out_data); private: KernelGlobals *kernel_globals; -#ifdef WITH_PARTIO - /* OSL gets pointers to this but its definition is private. - * right now it only caches the types already converted to - * Partio constants. this is what get_pointcloud_attr_query - * returns */ - struct AttrQuery { - /* names of the attributes to query */ - std::vector attr_names; - /* types as (enum Partio::ParticleAttributeType) of the - * attributes in the query */ - std::vector attr_partio_types; - /* for sanity checks, capacity of the output arrays */ - int capacity; - }; - - Partio::ParticlesData *get_pointcloud(ustring filename); - - /* keep a list so adding elements doesn't invalidate pointers */ - std::list m_attr_queries; -#endif - static ustring u_distance; static ustring u_index; static ustring u_camera; diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp index d8d510a7c9b..345614c2868 100644 --- a/intern/cycles/kernel/osl/osl_shader.cpp +++ b/intern/cycles/kernel/osl/osl_shader.cpp @@ -36,25 +36,25 @@ tls_ptr(OSLGlobals::ThreadData, OSLGlobals::thread_data); void OSLShader::thread_init(KernelGlobals *kg) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = new OSLGlobals::ThreadData(); memset(&tdata->globals, 0, sizeof(OSL::ShaderGlobals)); - tdata->thread_info = ssi->create_thread_info(); + tdata->thread_info = ss->create_thread_info(); tls_set(kg->osl.thread_data, tdata); - ((OSLRenderServices *)ssi->renderer())->thread_init(kg); + kg->osl.services->thread_init(kg); } void OSLShader::thread_free(KernelGlobals *kg) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); - ssi->destroy_thread_info(tdata->thread_info); + ss->destroy_thread_info(tdata->thread_info); delete tdata; } @@ -123,7 +123,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sc.weight = weight; switch (prim->category()) { - case ClosurePrimitive::BSDF: { + case OSL::ClosurePrimitive::BSDF: { if (sd->num_closure == MAX_CLOSURE) return; @@ -137,11 +137,9 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, /* sample weight */ float albedo = bsdf->albedo(TO_VEC3(sd->I)); float sample_weight = fabsf(average(weight)) * albedo; - float sample_sum = sd->osl_closure.bsdf_sample_sum + sample_weight; sc.sample_weight = sample_weight; sc.type = CLOSURE_BSDF_ID; - sd->osl_closure.bsdf_sample_sum = sample_sum; /* scattering flags */ if (scattering == OSL::Labels::DIFFUSE) @@ -155,17 +153,15 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sd->closure[sd->num_closure++] = sc; break; } - case ClosurePrimitive::Emissive: { + case OSL::ClosurePrimitive::Emissive: { if (sd->num_closure == MAX_CLOSURE) return; /* sample weight */ float sample_weight = fabsf(average(weight)); - float sample_sum = sd->osl_closure.emissive_sample_sum + sample_weight; sc.sample_weight = sample_weight; sc.type = CLOSURE_EMISSION_ID; - sd->osl_closure.emissive_sample_sum = sample_sum; /* flag */ sd->flag |= SD_EMISSION; @@ -173,7 +169,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sd->closure[sd->num_closure++] = sc; break; } - case ClosurePrimitive::Holdout: + case OSL::ClosurePrimitive::Holdout: if (sd->num_closure == MAX_CLOSURE) return; @@ -182,11 +178,11 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sd->flag |= SD_HOLDOUT; sd->closure[sd->num_closure++] = sc; break; - case ClosurePrimitive::BSSRDF: - case ClosurePrimitive::Debug: + case OSL::ClosurePrimitive::BSSRDF: + case OSL::ClosurePrimitive::Debug: break; /* not implemented */ - case ClosurePrimitive::Background: - case ClosurePrimitive::Volume: + case OSL::ClosurePrimitive::Background: + case OSL::ClosurePrimitive::Volume: break; /* not relevant */ } } @@ -205,10 +201,10 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info); /* setup shader globals from shader data */ sd->osl_ctx = ctx; @@ -218,7 +214,7 @@ void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int int shader = sd->shader & SHADER_MASK; if (kg->osl.surface_state[shader]) - ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.surface_state[shader]), *globals); + ss->execute(*ctx, *(kg->osl.surface_state[shader]), *globals); /* flatten closure tree */ sd->num_closure = 0; @@ -263,10 +259,10 @@ static float3 flatten_background_closure_tree(const OSL::ClosureColor *closure) float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info); /* setup shader globals from shader data */ sd->osl_ctx = ctx; @@ -274,7 +270,7 @@ float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_fl /* execute shader for this point */ if (kg->osl.background_state) - ctx->execute(OSL::pvt::ShadUseSurface, *kg->osl.background_state, *globals); + ss->execute(*ctx, *(kg->osl.background_state), *globals); /* return background color immediately */ if (globals->Ci) @@ -301,29 +297,27 @@ static void flatten_volume_closure_tree(ShaderData *sd, sc.weight = weight; switch (prim->category()) { - case ClosurePrimitive::Volume: { + case OSL::ClosurePrimitive::Volume: { if (sd->num_closure == MAX_CLOSURE) return; /* sample weight */ float sample_weight = fabsf(average(weight)); - float sample_sum = sd->osl_closure.volume_sample_sum + sample_weight; sc.sample_weight = sample_weight; sc.type = CLOSURE_VOLUME_ID; - sd->osl_closure.volume_sample_sum = sample_sum; /* add */ sd->closure[sd->num_closure++] = sc; break; } - case ClosurePrimitive::Holdout: - case ClosurePrimitive::Debug: + case OSL::ClosurePrimitive::Holdout: + case OSL::ClosurePrimitive::Debug: break; /* not implemented */ - case ClosurePrimitive::Background: - case ClosurePrimitive::BSDF: - case ClosurePrimitive::Emissive: - case ClosurePrimitive::BSSRDF: + case OSL::ClosurePrimitive::Background: + case OSL::ClosurePrimitive::BSDF: + case OSL::ClosurePrimitive::Emissive: + case OSL::ClosurePrimitive::BSSRDF: break; /* not relevant */ } } @@ -342,10 +336,10 @@ static void flatten_volume_closure_tree(ShaderData *sd, void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info); /* setup shader globals from shader data */ sd->osl_ctx = ctx; @@ -355,12 +349,7 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int int shader = sd->shader & SHADER_MASK; if (kg->osl.volume_state[shader]) - ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.volume_state[shader]), *globals); - - /* retrieve resulting closures */ - sd->osl_closure.volume_sample_sum = 0.0f; - sd->osl_closure.num_volume = 0; - sd->osl_closure.randb = randb; + ss->execute(*ctx, *(kg->osl.volume_state[shader]), *globals); if (globals->Ci) flatten_volume_closure_tree(sd, globals->Ci); @@ -371,10 +360,10 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; - OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); + OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info); /* setup shader globals from shader data */ sd->osl_ctx = ctx; @@ -384,7 +373,7 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) int shader = sd->shader & SHADER_MASK; if (kg->osl.displacement_state[shader]) - ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.displacement_state[shader]), *globals); + ss->execute(*ctx, *(kg->osl.displacement_state[shader]), *globals); /* get back position */ sd->P = TO_FLOAT3(globals->P); @@ -392,10 +381,11 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) void OSLShader::release(KernelGlobals *kg, const ShaderData *sd) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; + OSL::ShadingSystem *ss = kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); + OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info); - ssi->release_context((OSL::pvt::ShadingContext *)sd->osl_ctx, tdata->thread_info); + ss->release_context(ctx); } /* BSDF Closure */ @@ -458,9 +448,8 @@ float3 OSLShader::emissive_eval(const ShaderData *sd, const ShaderClosure *sc) { OSL::EmissiveClosure *emissive = (OSL::EmissiveClosure *)sc->prim; OSL::Color3 emissive_eval = emissive->eval(TO_VEC3(sd->Ng), TO_VEC3(sd->I)); - eval += TO_FLOAT3(emissive_eval); - return eval; + return TO_FLOAT3(emissive_eval); } /* Volume Closure */ diff --git a/intern/cycles/kernel/svm/svm_geometry.h b/intern/cycles/kernel/svm/svm_geometry.h index 3cfce1d087a..22741bdb067 100644 --- a/intern/cycles/kernel/svm/svm_geometry.h +++ b/intern/cycles/kernel/svm/svm_geometry.h @@ -98,25 +98,47 @@ __device void svm_node_object_info(KernelGlobals *kg, ShaderData *sd, float *sta __device void svm_node_particle_info(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset) { - float data; - switch(type) { case NODE_INFO_PAR_INDEX: { uint particle_id = object_particle_id(kg, sd->object); - data = particle_index(kg, particle_id); - stack_store_float(stack, out_offset, data); + stack_store_float(stack, out_offset, particle_index(kg, particle_id)); break; } case NODE_INFO_PAR_AGE: { uint particle_id = object_particle_id(kg, sd->object); - data = particle_age(kg, particle_id); - stack_store_float(stack, out_offset, data); + stack_store_float(stack, out_offset, particle_age(kg, particle_id)); break; } case NODE_INFO_PAR_LIFETIME: { uint particle_id = object_particle_id(kg, sd->object); - data = particle_lifetime(kg, particle_id); - stack_store_float(stack, out_offset, data); + stack_store_float(stack, out_offset, particle_lifetime(kg, particle_id)); + break; + } + case NODE_INFO_PAR_LOCATION: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float3(stack, out_offset, particle_location(kg, particle_id)); + break; + } + #if 0 /* XXX float4 currently not supported in SVM stack */ + case NODE_INFO_PAR_ROTATION: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float4(stack, out_offset, particle_rotation(kg, particle_id)); + break; + } + #endif + case NODE_INFO_PAR_SIZE: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float(stack, out_offset, particle_size(kg, particle_id)); + break; + } + case NODE_INFO_PAR_VELOCITY: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float3(stack, out_offset, particle_velocity(kg, particle_id)); + break; + } + case NODE_INFO_PAR_ANGULAR_VELOCITY: { + uint particle_id = object_particle_id(kg, sd->object); + stack_store_float3(stack, out_offset, particle_angular_velocity(kg, particle_id)); break; } } diff --git a/intern/cycles/kernel/svm/svm_math.h b/intern/cycles/kernel/svm/svm_math.h index bc2f774097e..e39c7a4ba6c 100644 --- a/intern/cycles/kernel/svm/svm_math.h +++ b/intern/cycles/kernel/svm/svm_math.h @@ -108,6 +108,8 @@ __device float svm_math(NodeMath type, float Fac1, float Fac2) Fac = Fac1 < Fac2; else if(type == NODE_MATH_GREATER_THAN) Fac = Fac1 > Fac2; + else if(type == NODE_MATH_CLAMP) + Fac = clamp(Fac1, 0.0f, 1.0f); else Fac = 0.0f; diff --git a/intern/cycles/kernel/svm/svm_mix.h b/intern/cycles/kernel/svm/svm_mix.h index 6b455e713c2..888e4d9645e 100644 --- a/intern/cycles/kernel/svm/svm_mix.h +++ b/intern/cycles/kernel/svm/svm_mix.h @@ -276,6 +276,17 @@ __device float3 svm_mix_linear(float t, float3 col1, float3 col2) return outcol; } +__device float3 svm_mix_clamp(float3 col) +{ + float3 outcol = col; + + outcol.x = clamp(col.x, 0.0f, 1.0f); + outcol.y = clamp(col.y, 0.0f, 1.0f); + outcol.z = clamp(col.z, 0.0f, 1.0f); + + return outcol; +} + __device float3 svm_mix(NodeMix type, float fac, float3 c1, float3 c2) { float t = clamp(fac, 0.0f, 1.0f); @@ -299,6 +310,7 @@ __device float3 svm_mix(NodeMix type, float fac, float3 c1, float3 c2) case NODE_MIX_COLOR: return svm_mix_color(t, c1, c2); case NODE_MIX_SOFT: return svm_mix_soft(t, c1, c2); case NODE_MIX_LINEAR: return svm_mix_linear(t, c1, c2); + case NODE_MIX_CLAMP: return svm_mix_clamp(c1); } return make_float3(0.0f, 0.0f, 0.0f); diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h index 854a708a988..fbaf253177d 100644 --- a/intern/cycles/kernel/svm/svm_tex_coord.h +++ b/intern/cycles/kernel/svm/svm_tex_coord.h @@ -29,7 +29,7 @@ __device_inline float3 svm_background_offset(KernelGlobals *kg) __device_inline float3 svm_world_to_ndc(KernelGlobals *kg, ShaderData *sd, float3 P) { if(kernel_data.cam.type != CAMERA_PANORAMA) { - if(sd->object != ~0) + if(sd->object == ~0) P += svm_background_offset(kg); Transform tfm = kernel_data.cam.worldtondc; diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index a577f8b12f7..c82eafc790a 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -118,7 +118,12 @@ typedef enum NodeObjectInfo { typedef enum NodeParticleInfo { NODE_INFO_PAR_INDEX, NODE_INFO_PAR_AGE, - NODE_INFO_PAR_LIFETIME + NODE_INFO_PAR_LIFETIME, + NODE_INFO_PAR_LOCATION, + NODE_INFO_PAR_ROTATION, + NODE_INFO_PAR_SIZE, + NODE_INFO_PAR_VELOCITY, + NODE_INFO_PAR_ANGULAR_VELOCITY } NodeParticleInfo; typedef enum NodeLightPath { @@ -165,7 +170,8 @@ typedef enum NodeMix { NODE_MIX_VAL, NODE_MIX_COLOR, NODE_MIX_SOFT, - NODE_MIX_LINEAR + NODE_MIX_LINEAR, + NODE_MIX_CLAMP /* used for the clamp UI option */ } NodeMix; typedef enum NodeMath { @@ -185,7 +191,8 @@ typedef enum NodeMath { NODE_MATH_MAXIMUM, NODE_MATH_ROUND, NODE_MATH_LESS_THAN, - NODE_MATH_GREATER_THAN + NODE_MATH_GREATER_THAN, + NODE_MATH_CLAMP /* used for the clamp UI option */ } NodeMath; typedef enum NodeVectorMath { diff --git a/intern/cycles/render/CMakeLists.txt b/intern/cycles/render/CMakeLists.txt index 4d4fbfe6814..85b476e60d9 100644 --- a/intern/cycles/render/CMakeLists.txt +++ b/intern/cycles/render/CMakeLists.txt @@ -27,6 +27,7 @@ set(SRC nodes.cpp object.cpp osl.cpp + particles.cpp scene.cpp session.cpp shader.cpp @@ -51,6 +52,7 @@ set(SRC_HEADERS nodes.h object.h osl.h + particles.h scene.h session.h shader.h diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index ce715ad3893..20fbfa0cf27 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -55,6 +55,7 @@ ShaderNode::ShaderNode(const char *name_) name = name_; id = -1; bump = SHADER_BUMP_NONE; + special_type = SHADER_SPECIAL_TYPE_NONE; } ShaderNode::~ShaderNode() @@ -298,8 +299,8 @@ void ShaderGraph::copy_nodes(set& nodes, map& removed) { foreach(ShaderNode *node, nodes) { - ProxyNode *proxy = dynamic_cast(node); - if (proxy) { + if (node->special_type == SHADER_SPECIAL_TYPE_PROXY) { + ProxyNode *proxy = static_cast(node); ShaderInput *input = proxy->inputs[0]; ShaderOutput *output = proxy->outputs[0]; @@ -330,9 +331,8 @@ void ShaderGraph::remove_proxy_nodes(vector& removed) } /* remove useless mix closures nodes */ - MixClosureNode *mix = dynamic_cast(node); - - if(mix) { + if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) { + MixClosureNode *mix = static_cast(node); if(mix->outputs[0]->links.size() && mix->inputs[1]->link == mix->inputs[2]->link) { ShaderOutput *output = mix->inputs[1]->link; vector inputs = mix->outputs[0]->links; diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h index 91ec83aba21..c3b674d0f23 100644 --- a/intern/cycles/render/graph.h +++ b/intern/cycles/render/graph.h @@ -63,6 +63,17 @@ enum ShaderBump { SHADER_BUMP_DY }; +/* Identifiers for some special node types. + * + * The graph needs to identify these in the clean function. + * Cannot use dynamic_cast, as this is disabled for OSL. */ + +enum ShaderNodeSpecialType { + SHADER_SPECIAL_TYPE_NONE, + SHADER_SPECIAL_TYPE_PROXY, + SHADER_SPECIAL_TYPE_MIX_CLOSURE +}; + /* Enum * * Utility class for enum values. */ @@ -167,6 +178,8 @@ public: ustring name; /* name, not required to be unique */ int id; /* index in graph node array */ ShaderBump bump; /* for bump mapping utility */ + + ShaderNodeSpecialType special_type; /* special node type */ }; diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index 9d221d56efb..6445c04257f 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -290,12 +290,12 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen device->tex_alloc("__light_distribution", dscene->light_distribution); } else { + dscene->light_distribution.clear(); + kintegrator->num_distribution = 0; + kintegrator->num_all_lights = 0; kintegrator->pdf_triangles = 0.0f; kintegrator->pdf_lights = 0.0f; - kintegrator->num_all_lights = 0; - - dscene->light_distribution.clear(); } } diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index b8678005438..da511b2d2f4 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -1153,6 +1153,7 @@ ProxyNode::ProxyNode(ShaderSocketType from_, ShaderSocketType to_) { from = from_; to = to_; + special_type = SHADER_SPECIAL_TYPE_PROXY; add_input("Input", from); add_output("Output", to); @@ -1918,6 +1919,13 @@ ParticleInfoNode::ParticleInfoNode() add_output("Index", SHADER_SOCKET_FLOAT); add_output("Age", SHADER_SOCKET_FLOAT); add_output("Lifetime", SHADER_SOCKET_FLOAT); + add_output("Location", SHADER_SOCKET_POINT); + #if 0 /* not yet supported */ + add_output("Rotation", SHADER_SOCKET_QUATERNION); + #endif + add_output("Size", SHADER_SOCKET_FLOAT); + add_output("Velocity", SHADER_SOCKET_VECTOR); + add_output("Angular Velocity", SHADER_SOCKET_VECTOR); } void ParticleInfoNode::attributes(AttributeRequestSet *attributes) @@ -1928,6 +1936,18 @@ void ParticleInfoNode::attributes(AttributeRequestSet *attributes) attributes->add(ATTR_STD_PARTICLE); if(!output("Lifetime")->links.empty()) attributes->add(ATTR_STD_PARTICLE); + if(!output("Location")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + #if 0 /* not yet supported */ + if(!output("Rotation")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + #endif + if(!output("Size")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + if(!output("Velocity")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + if(!output("Angular Velocity")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); ShaderNode::attributes(attributes); } @@ -1953,6 +1973,38 @@ void ParticleInfoNode::compile(SVMCompiler& compiler) compiler.stack_assign(out); compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LIFETIME, out->stack_offset); } + + out = output("Location"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LOCATION, out->stack_offset); + } + + #if 0 /* XXX Quaternion data is not yet supported by Cycles */ + out = output("Rotation"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ROTATION, out->stack_offset); + } + #endif + + out = output("Size"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_SIZE, out->stack_offset); + } + + out = output("Velocity"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_VELOCITY, out->stack_offset); + } + + out = output("Angular Velocity"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ANGULAR_VELOCITY, out->stack_offset); + } } void ParticleInfoNode::compile(OSLCompiler& compiler) @@ -2037,6 +2089,8 @@ void AddClosureNode::compile(OSLCompiler& compiler) MixClosureNode::MixClosureNode() : ShaderNode("mix_closure") { + special_type = SHADER_SPECIAL_TYPE_MIX_CLOSURE; + add_input("Fac", SHADER_SOCKET_FLOAT, 0.5f); add_input("Closure1", SHADER_SOCKET_CLOSURE); add_input("Closure2", SHADER_SOCKET_CLOSURE); @@ -2088,6 +2142,8 @@ MixNode::MixNode() { type = ustring("Mix"); + use_clamp = false; + add_input("Fac", SHADER_SOCKET_FLOAT, 0.5f); add_input("Color1", SHADER_SOCKET_COLOR); add_input("Color2", SHADER_SOCKET_COLOR); @@ -2136,11 +2192,17 @@ void MixNode::compile(SVMCompiler& compiler) compiler.add_node(NODE_MIX, fac_in->stack_offset, color1_in->stack_offset, color2_in->stack_offset); compiler.add_node(NODE_MIX, type_enum[type], color_out->stack_offset); + + if(use_clamp) { + compiler.add_node(NODE_MIX, 0, color_out->stack_offset); + compiler.add_node(NODE_MIX, NODE_MIX_CLAMP, color_out->stack_offset); + } } void MixNode::compile(OSLCompiler& compiler) { compiler.parameter("type", type); + compiler.parameter("Clamp", use_clamp); compiler.add(this, "node_mix"); } @@ -2466,7 +2528,7 @@ void LayerWeightNode::compile(SVMCompiler& compiler) void LayerWeightNode::compile(OSLCompiler& compiler) { - compiler.add(this, "node_layer_height"); + compiler.add(this, "node_blend_weight"); } /* Output */ @@ -2508,6 +2570,8 @@ MathNode::MathNode() { type = ustring("Add"); + use_clamp = false; + add_input("Value1", SHADER_SOCKET_FLOAT); add_input("Value2", SHADER_SOCKET_FLOAT); add_output("Value", SHADER_SOCKET_FLOAT); @@ -2552,11 +2616,17 @@ void MathNode::compile(SVMCompiler& compiler) compiler.add_node(NODE_MATH, type_enum[type], value1_in->stack_offset, value2_in->stack_offset); compiler.add_node(NODE_MATH, value_out->stack_offset); + + if(use_clamp) { + compiler.add_node(NODE_MATH, NODE_MATH_CLAMP, value_out->stack_offset); + compiler.add_node(NODE_MATH, value_out->stack_offset); + } } void MathNode::compile(OSLCompiler& compiler) { compiler.parameter("type", type); + compiler.parameter("Clamp", use_clamp); compiler.add(this, "node_math"); } diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index da5b90bfdda..82bead7e41a 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -340,6 +340,8 @@ class MixNode : public ShaderNode { public: SHADER_NODE_CLASS(MixNode) + bool use_clamp; + ustring type; static ShaderEnum type_enum; }; @@ -396,6 +398,8 @@ class MathNode : public ShaderNode { public: SHADER_NODE_CLASS(MathNode) + bool use_clamp; + ustring type; static ShaderEnum type_enum; }; diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index 0fe227fd171..7389b239627 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -249,38 +249,6 @@ void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene device->tex_alloc("__object_flag", dscene->object_flag); } -void ObjectManager::device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) -{ - /* count particles. - * adds one dummy particle at the beginning to avoid invalid lookups, - * in case a shader uses particle info without actual particle data. - */ - int num_particles = 1; - foreach(Object *ob, scene->objects) - num_particles += ob->particles.size(); - - float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles); - - /* dummy particle */ - particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - - int i = 1; - foreach(Object *ob, scene->objects) { - foreach(Particle &pa, ob->particles) { - /* pack in texture */ - int offset = i*PARTICLE_SIZE; - - particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, 0.0f); - - i++; - - if(progress.get_cancel()) return; - } - } - - device->tex_alloc("__particles", dscene->particles); -} - void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) { if(!need_update) @@ -306,11 +274,6 @@ void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *sc if(progress.get_cancel()) return; - progress.set_status("Updating Objects", "Copying Particles to device"); - device_update_particles(device, dscene, scene, progress); - - if(progress.get_cancel()) return; - need_update = false; } @@ -321,9 +284,6 @@ void ObjectManager::device_free(Device *device, DeviceScene *dscene) device->tex_free(dscene->object_flag); dscene->object_flag.clear(); - - device->tex_free(dscene->particles); - dscene->particles.clear(); } void ObjectManager::apply_static_transforms(Scene *scene, Progress& progress) diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h index 9b2f5bc8768..88677d79dff 100644 --- a/intern/cycles/render/object.h +++ b/intern/cycles/render/object.h @@ -35,12 +35,6 @@ struct Transform; /* Object */ -struct Particle { - int index; - float age; - float lifetime; -}; - class Object { public: Mesh *mesh; @@ -56,7 +50,6 @@ public: bool use_holdout; int particle_id; - vector particles; Object(); ~Object(); @@ -78,7 +71,6 @@ public: void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); void device_update_transforms(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); - void device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); void device_free(Device *device, DeviceScene *dscene); void tag_update(Scene *scene); diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index 04af9b48280..d4c93c07e2f 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -101,8 +101,9 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene /* setup shader engine */ og->ss = ss; + og->services = services; int background_id = scene->shader_manager->get_shader_id(scene->default_background); - og->background_state = og->surface_state[background_id]; + og->background_state = og->surface_state[background_id & SHADER_MASK]; og->use = true; tls_create(OSLGlobals::ThreadData, og->thread_data); diff --git a/intern/cycles/render/particles.cpp b/intern/cycles/render/particles.cpp new file mode 100644 index 00000000000..9f951d9673f --- /dev/null +++ b/intern/cycles/render/particles.cpp @@ -0,0 +1,123 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "device.h" +#include "particles.h" +#include "scene.h" + +#include "util_foreach.h" +#include "util_map.h" +#include "util_progress.h" +#include "util_vector.h" + +CCL_NAMESPACE_BEGIN + +/* Particle System */ + +ParticleSystem::ParticleSystem() +{ +} + +ParticleSystem::~ParticleSystem() +{ +} + +void ParticleSystem::tag_update(Scene *scene) +{ + scene->particle_system_manager->need_update = true; +} + +/* Particle System Manager */ + +ParticleSystemManager::ParticleSystemManager() +{ + need_update = true; +} + +ParticleSystemManager::~ParticleSystemManager() +{ +} + +void ParticleSystemManager::device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) +{ + /* count particles. + * adds one dummy particle at the beginning to avoid invalid lookups, + * in case a shader uses particle info without actual particle data. + */ + int num_particles = 1; + foreach(ParticleSystem *psys, scene->particle_systems) + num_particles += psys->particles.size(); + + float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles); + + /* dummy particle */ + particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[3] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + particles[4] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + + int i = 1; + foreach(ParticleSystem *psys, scene->particle_systems) { + foreach(Particle &pa, psys->particles) { + /* pack in texture */ + int offset = i*PARTICLE_SIZE; + + particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, pa.size); + particles[offset+1] = pa.rotation; + particles[offset+2] = make_float4(pa.location.x, pa.location.y, pa.location.z, pa.velocity.x); + particles[offset+3] = make_float4(pa.velocity.y, pa.velocity.z, pa.angular_velocity.x, pa.angular_velocity.y); + particles[offset+4] = make_float4(pa.angular_velocity.z, 0.0f, 0.0f, 0.0f); + + i++; + + if(progress.get_cancel()) return; + } + } + + device->tex_alloc("__particles", dscene->particles); +} + +void ParticleSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) +{ + if(!need_update) + return; + + device_free(device, dscene); + + progress.set_status("Updating Particle Systems", "Copying Particles to device"); + device_update_particles(device, dscene, scene, progress); + + if(progress.get_cancel()) return; + + need_update = false; +} + +void ParticleSystemManager::device_free(Device *device, DeviceScene *dscene) +{ + device->tex_free(dscene->particles); + dscene->particles.clear(); +} + +void ParticleSystemManager::tag_update(Scene *scene) +{ + need_update = true; +} + +CCL_NAMESPACE_END + diff --git a/intern/cycles/render/particles.h b/intern/cycles/render/particles.h new file mode 100644 index 00000000000..afc8b2b2dcb --- /dev/null +++ b/intern/cycles/render/particles.h @@ -0,0 +1,74 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __PARTICLES_H__ +#define __PARTICLES_H__ + +#include "util_types.h" +#include "util_vector.h" + +CCL_NAMESPACE_BEGIN + +class Device; +class DeviceScene; +class Progress; +class Scene; + +/* Particle System */ + +struct Particle { + int index; + float age; + float lifetime; + float3 location; + float4 rotation; + float size; + float3 velocity; + float3 angular_velocity; +}; + +class ParticleSystem { +public: + ParticleSystem(); + ~ParticleSystem(); + + void tag_update(Scene *scene); + + vector particles; +}; + +/* ParticleSystem Manager */ + +class ParticleSystemManager { +public: + bool need_update; + + ParticleSystemManager(); + ~ParticleSystemManager(); + + void device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); + void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); + void device_free(Device *device, DeviceScene *dscene); + + void tag_update(Scene *scene); +}; + +CCL_NAMESPACE_END + +#endif /* __PARTICLES_H__ */ + diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp index 33ebd7a59ef..071338d49c2 100644 --- a/intern/cycles/render/scene.cpp +++ b/intern/cycles/render/scene.cpp @@ -28,6 +28,7 @@ #include "shader.h" #include "mesh.h" #include "object.h" +#include "particles.h" #include "scene.h" #include "svm.h" #include "osl.h" @@ -53,6 +54,7 @@ Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_) integrator = new Integrator(); image_manager = new ImageManager(); shader_manager = ShaderManager::create(this); + particle_system_manager = new ParticleSystemManager(); if (device_info_.type == DEVICE_CPU) image_manager->set_extended_image_limits(); @@ -95,9 +97,14 @@ Scene::~Scene() delete o; foreach(Light *l, lights) delete l; + foreach(ParticleSystem *p, particle_systems) + delete p; if(device) image_manager->device_free(device, &dscene); delete image_manager; + + if(device) particle_system_manager->device_free(device, &dscene); + delete particle_system_manager; } void Scene::device_update(Device *device_, Progress& progress) @@ -152,6 +159,11 @@ void Scene::device_update(Device *device_, Progress& progress) if(progress.get_cancel()) return; + progress.set_status("Updating Particle Systems"); + particle_system_manager->device_update(device, &dscene, this, progress); + + if(progress.get_cancel()) return; + progress.set_status("Updating Filter"); filter->device_update(device, &dscene); @@ -213,7 +225,8 @@ bool Scene::need_reset() || light_manager->need_update || filter->need_update || integrator->need_update - || shader_manager->need_update); + || shader_manager->need_update + || particle_system_manager->need_update); } CCL_NAMESPACE_END diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h index 1a9540b319d..f6c1ef44146 100644 --- a/intern/cycles/render/scene.h +++ b/intern/cycles/render/scene.h @@ -47,6 +47,8 @@ class Mesh; class MeshManager; class Object; class ObjectManager; +class ParticleSystemManager; +class ParticleSystem; class Shader; class ShaderManager; class Progress; @@ -155,6 +157,7 @@ public: vector meshes; vector shaders; vector lights; + vector particle_systems; /* data managers */ ImageManager *image_manager; @@ -162,6 +165,7 @@ public: ShaderManager *shader_manager; MeshManager *mesh_manager; ObjectManager *object_manager; + ParticleSystemManager *particle_system_manager; /* default shaders */ int default_surface; diff --git a/intern/ghost/intern/GHOST_DropTargetWin32.cpp b/intern/ghost/intern/GHOST_DropTargetWin32.cpp index 4142b19f21d..89e9a91b34c 100644 --- a/intern/ghost/intern/GHOST_DropTargetWin32.cpp +++ b/intern/ghost/intern/GHOST_DropTargetWin32.cpp @@ -51,14 +51,10 @@ GHOST_DropTargetWin32::GHOST_DropTargetWin32(GHOST_WindowWin32 *window, GHOST_Sy m_cRef = 1; m_hWnd = window->getHWND(); m_draggedObjectType = GHOST_kDragnDropTypeUnknown; - - // register our window as drop target - ::RegisterDragDrop(m_hWnd, this); } GHOST_DropTargetWin32::~GHOST_DropTargetWin32() { - ::RevokeDragDrop(m_hWnd); } diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index 6c201c24c3d..52ebaf02404 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -724,7 +724,7 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINP int r; GetKeyboardState((PBYTE)state); - if (r = ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout)) { + if ((r = ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout))) { if ((r > 0 && r < 3)) { utf16[r] = 0; conv_utf_16_to_8(utf16, utf8_char, 6); diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp index 3a6e646de11..71a9db349ee 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cpp +++ b/intern/ghost/intern/GHOST_WindowWin32.cpp @@ -271,6 +271,10 @@ GHOST_WindowWin32::GHOST_WindowWin32( // Register this window as a droptarget. Requires m_hWnd to be valid. // Note that OleInitialize(0) has to be called prior to this. Done in GHOST_SystemWin32. m_dropTarget = new GHOST_DropTargetWin32(this, m_system); + if (m_dropTarget) { + ::RegisterDragDrop(m_hWnd, m_dropTarget); + } + // Store a pointer to this class in the window structure ::SetWindowLongPtr(m_hWnd, GWL_USERDATA, (LONG_PTR) this); @@ -415,7 +419,13 @@ GHOST_WindowWin32::~GHOST_WindowWin32() m_hDC = 0; } if (m_hWnd) { - m_dropTarget->Release(); // frees itself. + if (m_dropTarget) { + // Disable DragDrop + RevokeDragDrop(m_hWnd); + // Release our reference of the DropTarget and it will delete itself eventually. + m_dropTarget->Release(); + } + ::DestroyWindow(m_hWnd); m_hWnd = 0; } diff --git a/intern/guardedalloc/intern/mmap_win.c b/intern/guardedalloc/intern/mmap_win.c index a133f92fec4..ab50edb811e 100644 --- a/intern/guardedalloc/intern/mmap_win.c +++ b/intern/guardedalloc/intern/mmap_win.c @@ -44,7 +44,7 @@ #define FILE_MAP_EXECUTE 0x0020 #endif -/* copied from BKE_utildefines.h ugh */ +/* copied from BLI_utildefines.h, ugh */ #ifdef __GNUC__ # define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) #else diff --git a/intern/opennl/intern/opennl.c b/intern/opennl/intern/opennl.c index 20b4c0a6681..71809cc7480 100644 --- a/intern/opennl/intern/opennl.c +++ b/intern/opennl/intern/opennl.c @@ -569,6 +569,8 @@ void nlDeleteContext(NLContext context_in) { __NL_DELETE(context->variable[i].a); } } + + __NL_DELETE_ARRAY(context->variable); } if(context->alloc_b) { __NL_DELETE_ARRAY(context->b); diff --git a/release/scripts/startup/bl_operators/object_quick_effects.py b/release/scripts/startup/bl_operators/object_quick_effects.py index 62844d11443..35b496b6dd0 100644 --- a/release/scripts/startup/bl_operators/object_quick_effects.py +++ b/release/scripts/startup/bl_operators/object_quick_effects.py @@ -510,6 +510,6 @@ class QuickFluid(Operator): mat.raytrace_transparency.depth = 4 if self.start_baking: - bpy.ops.fluid.bake() + bpy.ops.fluid.bake('INVOKE_DEFAULT') return {'FINISHED'} diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index da916067302..b6a98faa48c 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -41,8 +41,6 @@ #include "DNA_vec_types.h" -#include "BKE_utildefines.h" - #include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_path_util.h" diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 64512dcaac8..fa9223ba6e2 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -698,6 +698,7 @@ void DM_init_origspace(DerivedMesh *dm); #ifndef NDEBUG char *DM_debug_info(DerivedMesh *dm); void DM_debug_print(DerivedMesh *dm); +void DM_debug_print_cdlayers(CustomData *cdata); #endif #endif diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index acb9234b2d4..d1908fe7a3a 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -60,7 +60,6 @@ void animviz_calc_motionpaths(struct Scene *scene, ListBase *targets); void free_path(struct Path *path); void calc_curvepath(struct Object *ob); -int interval_test(int min, int max, int p1, int cycl); int where_on_path(struct Object *ob, float ctime, float vec[4], float dir[3], float quat[4], float *radius, float *weight); /* ---------------------------------------------------- */ diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h index 0ed2db2aad2..63f5ec59a0b 100644 --- a/source/blender/blenkernel/BKE_utildefines.h +++ b/source/blender/blenkernel/BKE_utildefines.h @@ -15,13 +15,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * * ***** END GPL LICENSE BLOCK ***** */ @@ -39,48 +32,7 @@ extern "C" { #endif -/* these values need to be hardcoded in structs, dna does not recognize defines */ -/* also defined in DNA_space_types.h */ -#ifndef FILE_MAXDIR -#define FILE_MAXDIR 768 -#define FILE_MAXFILE 256 -#define FILE_MAX 1024 -#endif - -/* this weirdo pops up in two places ... */ -#if !defined(WIN32) -# ifndef O_BINARY -# define O_BINARY 0 -# endif -#endif - -/* INTEGER CODES */ -#ifdef __BIG_ENDIAN__ -/* Big Endian */ -# define MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) -#else -/* Little Endian */ -# define MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) -#endif - -#define DATA MAKE_ID('D', 'A', 'T', 'A') -#define GLOB MAKE_ID('G', 'L', 'O', 'B') - -#define DNA1 MAKE_ID('D', 'N', 'A', '1') -#define TEST MAKE_ID('T', 'E', 'S', 'T') /* used as preview between 'REND' and 'GLOB' */ -#define REND MAKE_ID('R', 'E', 'N', 'D') -#define USER MAKE_ID('U', 'S', 'E', 'R') - -#define ENDB MAKE_ID('E', 'N', 'D', 'B') - -/* Bit operations */ -#define BTST(a, b) ( ( (a) & 1 << (b) ) != 0) -#define BNTST(a, b) ( ( (a) & 1 << (b) ) == 0) -#define BTST2(a, b, c) (BTST( (a), (b) ) || BTST( (a), (c) ) ) -#define BSET(a, b) ( (a) | 1 << (b) ) -#define BCLR(a, b) ( (a) & ~(1 << (b)) ) -/* bit-row */ -#define BROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << (max + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) +/* currently unused but we may want to add macros here for BKE later */ #ifdef __cplusplus } diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index a29484638c0..1aa54307841 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -3187,4 +3187,25 @@ void DM_debug_print(DerivedMesh *dm) MEM_freeN(str); } +void DM_debug_print_cdlayers(CustomData *data) +{ + int i; + CustomDataLayer *layer; + + printf("{\n"); + + for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) { + + const char *name = CustomData_layertype_name(layer->type); + const int size = CustomData_sizeof(layer->type); + const char *structname; + int structnum; + CustomData_file_write_info(layer->type, &structname, &structnum); + printf(" dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n", + name, structname, layer->type, (void *)layer->data, size, (int)(MEM_allocN_len(layer->data) / size)); + } + + printf("}\n"); +} + #endif /* NDEBUG */ diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 9b4f0a31e28..f9954ff1dd0 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -63,7 +63,6 @@ #include "BKE_object.h" #include "BKE_particle.h" #include "BKE_scene.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_depsgraph.h" #include "BKE_anim.h" @@ -494,36 +493,42 @@ void calc_curvepath(Object *ob) /* in a path vertices are with equal differences: path->len = number of verts */ /* NOW WITH BEVELCURVE!!! */ - if (ob == NULL || ob->type != OB_CURVE) return; + if (ob == NULL || ob->type != OB_CURVE) { + return; + } cu = ob->data; - nurbs = BKE_curve_nurbs_get(cu); - nu = nurbs->first; - if (cu->path) free_path(cu->path); cu->path = NULL; + /* weak! can only use first curve */ bl = cu->bev.first; - if (bl == NULL || !bl->nr) return; + if (bl == NULL || !bl->nr) { + return; + } + + nurbs = BKE_curve_nurbs_get(cu); + nu = nurbs->first; cu->path = path = MEM_callocN(sizeof(Path), "calc_curvepath"); /* if POLY: last vertice != first vertice */ cycl = (bl->poly != -1); - if (cycl) tot = bl->nr; - else tot = bl->nr - 1; + tot = cycl ? bl->nr : bl->nr - 1; path->len = tot + 1; /* exception: vector handle paths and polygon paths should be subdivided at least a factor resolu */ - if (path->len < nu->resolu * SEGMENTSU(nu)) path->len = nu->resolu * SEGMENTSU(nu); + if (path->len < nu->resolu * SEGMENTSU(nu)) { + path->len = nu->resolu * SEGMENTSU(nu); + } dist = (float *)MEM_mallocN((tot + 1) * 4, "calcpathdist"); /* all lengths in *dist */ bevp = bevpfirst = (BevPoint *)(bl + 1); fp = dist; - *fp = 0; + *fp = 0.0f; for (a = 0; a < tot; a++) { fp++; if (cycl && a == tot - 1) @@ -558,19 +563,16 @@ void calc_curvepath(Object *ob) fp++; if (bevp < bevplast) bevp++; bevpn = bevp + 1; - if (bevpn > bevplast) { - if (cycl) bevpn = bevpfirst; - else bevpn = bevplast; + if (UNLIKELY(bevpn > bevplast)) { + bevpn = cycl ? bevpfirst : bevplast; } } - fac1 = *(fp) - *(fp - 1); - fac2 = *(fp) - d; - fac1 = fac2 / fac1; + fac1 = (*(fp) - d) / (*(fp) - *(fp - 1)); fac2 = 1.0f - fac1; - + interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2); - pp->vec[3] = fac1 * bevp->alfa + fac2 * bevpn->alfa; + pp->vec[3] = fac1 * bevp->alfa + fac2 * bevpn->alfa; pp->radius = fac1 * bevp->radius + fac2 * bevpn->radius; pp->weight = fac1 * bevp->weight + fac2 * bevpn->weight; interp_qt_qtqt(pp->quat, bevp->quat, bevpn->quat, fac2); @@ -582,18 +584,14 @@ void calc_curvepath(Object *ob) MEM_freeN(dist); } - -/* is this only used internally?*/ -int interval_test(int min, int max, int p1, int cycl) +static int interval_test(const int min, const int max, int p1, const int cycl) { if (cycl) { - if (p1 < min) - p1 = ((p1 - min) % (max - min + 1)) + max + 1; - else if (p1 > max) - p1 = ((p1 - min) % (max - min + 1)) + min; + if (p1 < min) p1 = ((p1 - min) % (max - min + 1)) + max + 1; + else if (p1 > max) p1 = ((p1 - min) % (max - min + 1)) + min; } else { - if (p1 < min) p1 = min; + if (p1 < min) p1 = min; else if (p1 > max) p1 = max; } return p1; diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index a4bf7bd9720..6a3dae93639 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -59,7 +59,6 @@ #include "BKE_main.h" #include "BKE_library.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -621,15 +620,30 @@ static char *rna_path_rename_fix(ID *owner_id, const char *prefix, const char *o } /* Check RNA-Paths for a list of F-Curves */ -static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths) +static void fcurves_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, + const char *oldKey, const char *newKey, ListBase *curves, int verify_paths) { FCurve *fcu; /* we need to check every curve... */ for (fcu = curves->first; fcu; fcu = fcu->next) { - /* firstly, handle the F-Curve's own path */ - if (fcu->rna_path) - fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths); + if (fcu->rna_path) { + char *old_path = fcu->rna_path; + + /* firstly, handle the F-Curve's own path */ + fcu->rna_path = rna_path_rename_fix(owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); + + /* if path changed and the F-Curve is grouped, check if its group also needs renaming + * (i.e. F-Curve is first of a bone's F-Curves; hence renaming this should also trigger rename) + */ + if (fcu->rna_path != old_path) { + bActionGroup *agrp = fcu->grp; + + if ((agrp) && strcmp(oldName, agrp->name)==0) { + BLI_strncpy(agrp->name, newName, sizeof(agrp->name)); + } + } + } } } @@ -675,7 +689,8 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix } /* Fix all RNA-Paths for Actions linked to NLA Strips */ -static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths) +static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, const char *oldName, const char *newName, + const char *oldKey, const char *newKey, ListBase *strips, int verify_paths) { NlaStrip *strip; @@ -683,11 +698,11 @@ static void nlastrips_path_rename_fix(ID *owner_id, const char *prefix, char *ol for (strip = strips->first; strip; strip = strip->next) { /* fix strip's action */ if (strip->act) - fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->act->curves, verify_paths); /* ignore own F-Curves, since those are local... */ /* check sub-strips (if metas) */ - nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &strip->strips, verify_paths); + nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldKey, newKey, &strip->strips, verify_paths); } } @@ -717,16 +732,16 @@ void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, cons /* Active action and temp action */ if (adt->action) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->action->curves, verify_paths); if (adt->tmpact) - fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves, verify_paths); + fcurves_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &adt->tmpact->curves, verify_paths); /* Drivers - Drivers are really F-Curves */ drivers_path_rename_fix(owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths); /* NLA Data - Animation Data for Strips */ for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) - nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips, verify_paths); + nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, oldN, newN, &nlt->strips, verify_paths); /* free the temp names */ MEM_freeN(oldN); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 04585791135..aa834ff131b 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1551,7 +1551,7 @@ void BKE_armature_where_is(bArmature *arm) static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected) { bPose *pose = ob->pose, *frompose = from->pose; - bPoseChannel *pchan, *pchanp, pchanw; + bPoseChannel *pchan, *pchanp; bConstraint *con; int error = 0; @@ -1587,31 +1587,32 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { pchanp = BKE_pose_channel_find_name(frompose, pchan->name); - + if (UNLIKELY(pchanp == NULL)) { /* happens for proxies that become invalid because of a missing link * for regulat cases it shouldn't happen at all */ } else if (pchan->bone->layer & layer_protected) { ListBase proxylocal_constraints = {NULL, NULL}; - + bPoseChannel pchanw = {NULL}; + /* copy posechannel to temp, but restore important pointers */ pchanw = *pchanp; pchanw.prev = pchan->prev; pchanw.next = pchan->next; pchanw.parent = pchan->parent; pchanw.child = pchan->child; - + /* this is freed so copy a copy, else undo crashes */ if (pchanw.prop) { pchanw.prop = IDP_CopyProperty(pchanw.prop); - + /* use the values from the the existing props */ if (pchan->prop) { IDP_SyncGroupValues(pchanw.prop, pchan->prop); } } - + /* constraints - proxy constraints are flushed... local ones are added after * 1. extract constraints not from proxy (CONSTRAINT_PROXY_LOCAL) from pchan's constraints * 2. copy proxy-pchan's constraints on-to new @@ -1622,30 +1623,30 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected extract_proxylocal_constraints(&proxylocal_constraints, &pchan->constraints); copy_constraints(&pchanw.constraints, &pchanp->constraints, FALSE); BLI_movelisttolist(&pchanw.constraints, &proxylocal_constraints); - + /* constraints - set target ob pointer to own object */ for (con = pchanw.constraints.first; con; con = con->next) { bConstraintTypeInfo *cti = constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - + if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); - + for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == from) ct->tar = ob; } - + if (cti->flush_constraint_targets) cti->flush_constraint_targets(con, &targets, 0); } } - + /* free stuff from current channel */ BKE_pose_channel_free(pchan); - - /* the final copy */ + + /* copy data in temp back over to the cleaned-out (but still allocated) original channel */ *pchan = pchanw; } else { diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 06ba0b47587..02ce3a36b14 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -80,13 +80,10 @@ #include "BKE_sound.h" #include "RE_pipeline.h" - #include "BLO_undofile.h" #include "BLO_readfile.h" #include "BLO_writefile.h" -#include "BKE_utildefines.h" - #include "RNA_access.h" #include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 881caec8a58..b176ed429f8 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -50,7 +50,6 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_paint.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_curve.h" diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 00130dd3583..391891d3985 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -4514,7 +4514,7 @@ static void con_relink_id_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED * since we've got the actual ID block, let's just inline this * code. * - * See ID_NEW(a) in BKE_utildefines.h + * See ID_NEW(a) in DNA_ID.h */ if ((*idpoin) && (*idpoin)->newid) (*idpoin) = (void *)(*idpoin)->newid; diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index a00bea38e51..342ee5bba41 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -51,7 +51,6 @@ #include "BLI_mempool.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "BKE_customdata.h" #include "BKE_customdata_file.h" #include "BKE_global.h" diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c index 71801c4729f..78449879f72 100644 --- a/source/blender/blenkernel/intern/customdata_file.c +++ b/source/blender/blenkernel/intern/customdata_file.c @@ -32,6 +32,7 @@ #include "BLI_fileops.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BKE_customdata_file.h" #include "BKE_global.h" @@ -165,9 +166,9 @@ static int cdf_read_header(CDataFile *cdf) header->endian = cdf_endian(); if (cdf->switchendian) { - SWITCH_INT(header->type); - SWITCH_INT(header->totlayer); - SWITCH_INT(header->structbytes); + BLI_endian_switch_int32(&header->type); + BLI_endian_switch_int32(&header->totlayer); + BLI_endian_switch_int32(&header->structbytes); } if (!ELEM(header->type, CDF_TYPE_IMAGE, CDF_TYPE_MESH)) @@ -185,10 +186,10 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) { - SWITCH_INT(image->width); - SWITCH_INT(image->height); - SWITCH_INT(image->tile_size); - SWITCH_INT(image->structbytes); + BLI_endian_switch_int32(&image->width); + BLI_endian_switch_int32(&image->height); + BLI_endian_switch_int32(&image->tile_size); + BLI_endian_switch_int32(&image->structbytes); } offset += image->structbytes; @@ -200,7 +201,7 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) - SWITCH_INT(mesh->structbytes); + BLI_endian_switch_int32(&mesh->structbytes); offset += mesh->structbytes; mesh->structbytes = sizeof(CDataFileMeshHeader); @@ -219,10 +220,10 @@ static int cdf_read_header(CDataFile *cdf) return 0; if (cdf->switchendian) { - SWITCH_INT(layer->type); - SWITCH_INT(layer->datatype); - SWITCH_INT64(layer->datasize); - SWITCH_INT(layer->structbytes); + BLI_endian_switch_int32(&layer->type); + BLI_endian_switch_int32(&layer->datatype); + BLI_endian_switch_uint64(&layer->datasize); + BLI_endian_switch_int32(&layer->structbytes); } if (layer->datatype != CDF_DATA_FLOAT) @@ -317,20 +318,13 @@ int cdf_read_layer(CDataFile *cdf, CDataFileLayer *blay) int cdf_read_data(CDataFile *cdf, unsigned int size, void *data) { - float *fdata; - unsigned int a; - /* read data */ if (!fread(data, size, 1, cdf->readf)) return 0; /* switch endian if necessary */ if (cdf->switchendian) { - fdata = data; - - for (a = 0; a < size / sizeof(float); a++) { - SWITCH_INT(fdata[a]); - } + BLI_endian_switch_float_array(data, size / sizeof(float)); } return 1; diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 1b53f8980cb..b8d5294eabc 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -75,7 +75,6 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_tracking.h" -#include "BKE_utildefines.h" #include "depsgraph_private.h" diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 53c12d32bc1..b78ab9b28cd 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -55,7 +55,6 @@ #include "BKE_curve.h" #include "BKE_global.h" #include "BKE_object.h" -#include "BKE_utildefines.h" #include "RNA_access.h" diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 0ffd68c9079..8b35974ea62 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -50,7 +50,6 @@ #include "DNA_scene_types.h" #include "DNA_object_types.h" -#include "BKE_utildefines.h" #include "BKE_packedFile.h" #include "BKE_library.h" #include "BKE_font.h" diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 7456f9aab8b..8229df28ab8 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -293,18 +293,6 @@ static IDProperty *IDP_CopyArray(IDProperty *prop) return newp; } -/*taken from readfile.c*/ -#define SWITCH_LONGINT(a) { \ - char s_i, *p_i; \ - p_i = (char *)& (a); \ - s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; \ - s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; \ - s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; \ - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; \ - } (void)0 - - - /* ---------- String Type ------------ */ IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 6d0a67f520f..987963273bb 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -81,7 +81,6 @@ #include "BKE_scene.h" #include "BKE_node.h" #include "BKE_sequencer.h" /* seq_foreground_frame_get() */ -#include "BKE_utildefines.h" #include "BLF_api.h" diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 9f770e0a9a7..f099a79b520 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -107,7 +107,6 @@ #include "BKE_gpencil.h" #include "BKE_fcurve.h" #include "BKE_speaker.h" -#include "BKE_utildefines.h" #include "BKE_movieclip.h" #include "BKE_mask.h" diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index 065dc38c81e..4a8601df0b8 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -61,7 +61,6 @@ #include "BKE_sequencer.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" -#include "BKE_utildefines.h" unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index eebcf12a799..a4fec1c0de4 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -157,7 +157,7 @@ struct pgn_elements { /* Forward declarations */ static int vertid(const CORNER *c1, const CORNER *c2, PROCESS *p, MetaBall *mb); -static int setcenter(CENTERLIST *table[], int i, int j, int k); +static int setcenter(CENTERLIST *table[], const int i, const int j, const int k); static CORNER *setcorner(PROCESS *p, int i, int j, int k); static void converge(const float p1[3], const float p2[3], float v1, float v2, float (*function)(float, float, float), float p[3], MetaBall *mb, int f); diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 50628ac857a..aa7388abd58 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -70,7 +70,6 @@ #include "BKE_library.h" #include "BKE_global.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_movieclip.h" #include "BKE_image.h" /* openanim */ #include "BKE_tracking.h" diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 52b1e1b869c..ade418e409f 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -58,8 +58,6 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" -#include "BKE_utildefines.h" -#include "BKE_utildefines.h" #include "RNA_access.h" diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 66b0cff691e..b862a824d50 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -37,8 +37,6 @@ #include "BKE_image.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" - #include "BKE_global.h" // XXX TESTING #include "BLI_math_base.h" diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 9787a5025f7..03342d0f6d1 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -57,7 +57,6 @@ #include "BKE_packedFile.h" #include "BKE_report.h" #include "BKE_sound.h" -#include "BKE_utildefines.h" #ifdef _WIN32 #define open _open diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 1588ec10b55..5e12b15a658 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -69,7 +69,6 @@ #include "BKE_scene.h" #include "BKE_smoke.h" #include "BKE_softbody.h" -#include "BKE_utildefines.h" #include "BIK_api.h" diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index c440d21f56d..7d9d2f02c06 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -44,7 +44,6 @@ #include "DNA_object_types.h" #include "BLI_blenlib.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_library.h" diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 0abd3444c54..acf38ace00a 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -49,7 +49,6 @@ #include "BKE_main.h" #include "BKE_sequencer.h" #include "BKE_texture.h" -#include "BKE_utildefines.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" diff --git a/source/blender/blenkernel/intern/seqmodifier.c b/source/blender/blenkernel/intern/seqmodifier.c index 70f27db0f74..0a195210e38 100644 --- a/source/blender/blenkernel/intern/seqmodifier.c +++ b/source/blender/blenkernel/intern/seqmodifier.c @@ -43,7 +43,6 @@ #include "BKE_colortools.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index dcf72c37f52..9aaa9fd79e8 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -62,7 +62,6 @@ #include "BKE_fcurve.h" #include "BKE_scene.h" #include "BKE_mask.h" -#include "BKE_utildefines.h" #include "RNA_access.h" diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 2462de07a18..f340bcb5b1e 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -50,7 +50,6 @@ # include "AUD_C-API.h" #endif -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_sound.h" diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 2f54fe6cebd..ee904de4af6 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -56,7 +56,6 @@ #include "IMB_imbuf.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_ocean.h" diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 78e7dab045f..2ed9d992c3f 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -411,6 +411,8 @@ void BKE_tracking_clipboard_free(void) track = next_track; } + + tracking_clipboard.tracks.first = tracking_clipboard.tracks.last = NULL; } void BKE_tracking_clipboard_copy_tracks(MovieTracking *tracking, MovieTrackingObject *object) diff --git a/source/blender/blenlib/BLI_endian_switch.h b/source/blender/blenlib/BLI_endian_switch.h new file mode 100644 index 00000000000..7017e7ba789 --- /dev/null +++ b/source/blender/blenlib/BLI_endian_switch.h @@ -0,0 +1,42 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_ENDIAN_SWITCH_H__ +#define __BLI_ENDIAN_SWITCH_H__ + +/** \file BLI_endian_switch.h + * \ingroup bli + */ + +#include "BLI_endian_switch_inline.h" + +/* endian_switch.c */ +void BLI_endian_switch_int16_array(short *val, const int size); +void BLI_endian_switch_uint16_array(unsigned short *val, const int size); +void BLI_endian_switch_int32_array(int *val, const int size); +void BLI_endian_switch_uint32_array(unsigned int *val, const int size); +void BLI_endian_switch_float_array(float *val, const int size); +void BLI_endian_switch_int64_array(int64_t *val, const int size); +void BLI_endian_switch_uint64_array(uint64_t *val, const int size); +void BLI_endian_switch_double_array(double *val, const int size); + +#endif /* __BLI_ENDIAN_SWITCH_H__ */ diff --git a/source/blender/blenlib/BLI_endian_switch_inline.h b/source/blender/blenlib/BLI_endian_switch_inline.h new file mode 100644 index 00000000000..b747da3b738 --- /dev/null +++ b/source/blender/blenlib/BLI_endian_switch_inline.h @@ -0,0 +1,116 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/* only include from header */ +#ifndef __BLI_ENDIAN_SWITCH_H__ +# error "this file isnt to be directly included" +#endif + +#ifndef __BLI_ENDIAN_SWITCH_INLINE_H__ +#define __BLI_ENDIAN_SWITCH_INLINE_H__ + +/** \file blender/blenlib/BLI_endian_switch_inline.h + * \ingroup bli + */ + + +BLI_INLINE void BLI_endian_switch_int16(short *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; + p_i[0] = p_i[1]; + p_i[1] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; + p_i[0] = p_i[1]; + p_i[1] = s_i; +} + +BLI_INLINE void BLI_endian_switch_int32(int *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_float(float *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; + s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; +} + +BLI_INLINE void BLI_endian_switch_int64(int64_t *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; + s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; + s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; +} + +BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; + s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; + s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; +} + +BLI_INLINE void BLI_endian_switch_double(double *val) +{ + char *p_i = (char *)val; + char s_i; + + s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; + s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; + s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; + s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; +} + +#endif /* __BLI_ENDIAN_SWITCH_INLINE_H__ */ diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index ac0ec6a52a7..e8d6336a994 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -91,6 +91,13 @@ int BLI_file_older(const char *file1, const char *file2); struct LinkNode *BLI_file_read_as_lines(const char *file); void BLI_file_free_lines(struct LinkNode *lines); +/* this weirdo pops up in two places ... */ +#if !defined(WIN32) +# ifndef O_BINARY +# define O_BINARY 0 +# endif +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 35d7b8d9444..4bd21139545 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -193,6 +193,14 @@ void BLI_system_temporary_dir(char *dir); void BLI_string_to_utf8(char *original, char *utf_8, const char *code); #endif +/* these values need to be hardcoded in structs, dna does not recognize defines */ +/* also defined in DNA_space_types.h */ +#ifndef FILE_MAXDIR +# define FILE_MAXDIR 768 +# define FILE_MAXFILE 256 +# define FILE_MAX 1024 +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 8a459b9b07c..c11d8ed55be 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -225,30 +225,6 @@ (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot)) \ ) -/* This one rotates the bytes in an int64, int (32) and short (16) */ -#define SWITCH_INT64(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; \ - s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; \ - s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; \ - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; \ - } (void)0 - -#define SWITCH_INT(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; \ - s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; \ - } (void)0 - -#define SWITCH_SHORT(a) { \ - char s_i, *p_i; \ - p_i = (char *)&(a); \ - s_i = p_i[0]; p_i[0] = p_i[1]; p_i[1] = s_i; \ - } (void)0 - - /* Warning-free macros for storing ints in pointers. Use these _only_ * for storing an int in a pointer, not a pointer in an int (64bit)! */ #define SET_INT_IN_POINTER(i) ((void *)(intptr_t)(i)) diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 0175076fab8..fd755943e70 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -55,6 +55,7 @@ set(SRC intern/cpu.c intern/dynlib.c intern/edgehash.c + intern/endian_switch.c intern/fileops.c intern/fnmatch.c intern/freetypefont.c @@ -105,6 +106,8 @@ set(SRC BLI_dynlib.h BLI_dynstr.h BLI_edgehash.h + BLI_endian_switch.h + BLI_endian_switch_inline.h BLI_fileops.h BLI_fileops_types.h BLI_fnmatch.h diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c index 8c9993afee8..0ac6209fc95 100644 --- a/source/blender/blenlib/intern/BLI_memarena.c +++ b/source/blender/blenlib/intern/BLI_memarena.c @@ -46,7 +46,7 @@ struct MemArena { LinkNode *bufs; }; -MemArena *BLI_memarena_new(int bufsize, const char *name) +MemArena *BLI_memarena_new(const int bufsize, const char *name) { MemArena *ma = MEM_callocN(sizeof(*ma), "memarena"); ma->bufsize = bufsize; @@ -66,7 +66,7 @@ void BLI_memarena_use_malloc(MemArena *ma) ma->use_calloc = 0; } -void BLI_memarena_use_align(struct MemArena *ma, int align) +void BLI_memarena_use_align(struct MemArena *ma, const int align) { /* align should be a power of two */ ma->align = align; diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index c7e610edd9e..d98e63d88dd 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -45,7 +45,7 @@ #include #include -/* note: copied from BKE_utildefines.h, don't use here because we're in BLI */ +/* note: copied from BLO_blend_defs.h, don't use here because we're in BLI */ #ifdef __BIG_ENDIAN__ /* Big Endian */ # define MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 2a750cb1a66..be1f4eb3a35 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -78,7 +78,6 @@ #include "BKE_main.h" #include "BKE_report.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "BKE_image.h" /* so we can check the image's type */ static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src) diff --git a/source/blender/blenlib/intern/endian_switch.c b/source/blender/blenlib/intern/endian_switch.c new file mode 100644 index 00000000000..b9b18136863 --- /dev/null +++ b/source/blender/blenlib/intern/endian_switch.c @@ -0,0 +1,118 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenlib/intern/endian_switch.c + * \ingroup bli + */ + +#include "BLO_sys_types.h" +#include "BLI_utildefines.h" +#include "BLI_endian_switch.h" + +void BLI_endian_switch_int16_array(short *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int16(val--); + } + } +} + +void BLI_endian_switch_uint16_array(unsigned short *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint16(val--); + } + } +} + +void BLI_endian_switch_int32_array(int *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int32(val--); + } + } +} + +void BLI_endian_switch_uint32_array(unsigned int *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint32(val--); + } + } +} + +void BLI_endian_switch_float_array(float *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_float(val--); + } + } +} + +void BLI_endian_switch_int64_array(int64_t *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_int64(val--); + } + } +} + +void BLI_endian_switch_uint64_array(uint64_t *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_uint64(val--); + } + } +} + + +void BLI_endian_switch_double_array(double *val, const int size) +{ + if (size > 0) { + int i = size; + val = val + (size - 1); + while (i--) { + BLI_endian_switch_double(val--); + } + } +} diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 7aa956a0548..f3107b565b9 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -60,8 +60,6 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" - #include "BLO_sys_types.h" // for intptr_t support diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index e6ecdeae2e9..a7a66718445 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -47,7 +47,6 @@ #include "BLI_string_utf8.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "BKE_blender.h" // BLENDER_VERSION #include "GHOST_Path-api.h" diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 965e8b5eec3..0fccd91fc02 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -86,13 +86,10 @@ #include "BLI_listbase.h" #include "BLI_linklist.h" -#include "BLI_fileops.h" - -#include "BLI_fileops_types.h" #include "BLI_string.h" #include "BLI_fileops.h" - -#include "BKE_utildefines.h" +#include "BLI_fileops_types.h" +#include "BLI_path_util.h" /* vars: */ static int totnum, actnum; diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 0dc4d3c2db6..5b5f4cf8b80 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -41,12 +41,12 @@ #include "BLI_path_util.h" #include "BLI_string.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY #include "BLI_winstuff.h" #include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "utf_winfunc.h" #include "utfconv.h" diff --git a/source/blender/blenloader/BLO_blend_defs.h b/source/blender/blenloader/BLO_blend_defs.h new file mode 100644 index 00000000000..8005be158ce --- /dev/null +++ b/source/blender/blenloader/BLO_blend_defs.h @@ -0,0 +1,47 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef __BLO_BLEND_DEFS_H__ +#define __BLO_BLEND_DEFS_H__ + +/** \file BLO_blend_defs.h + * \ingroup blenloader + * \brief defines for blendfile codes + */ + +/* INTEGER CODES */ +#ifdef __BIG_ENDIAN__ +/* Big Endian */ +# define BLEND_MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) +#else +/* Little Endian */ +# define BLEND_MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) +#endif + +#define DATA BLEND_MAKE_ID('D', 'A', 'T', 'A') +#define GLOB BLEND_MAKE_ID('G', 'L', 'O', 'B') + +#define DNA1 BLEND_MAKE_ID('D', 'N', 'A', '1') +#define TEST BLEND_MAKE_ID('T', 'E', 'S', 'T') /* used as preview between 'REND' and 'GLOB' */ +#define REND BLEND_MAKE_ID('R', 'E', 'N', 'D') +#define USER BLEND_MAKE_ID('U', 'S', 'E', 'R') + +#define ENDB BLEND_MAKE_ID('E', 'N', 'D', 'B') + +#endif /* __BLO_BLEND_DEFS_H__ */ diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index a0fe042e7fb..74df5211dad 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -48,6 +48,7 @@ set(SRC intern/versioning_legacy.c intern/writefile.c + BLO_blend_defs.h BLO_readfile.h BLO_runtime.h BLO_soundfile.h diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index eb12a7bd837..e917ccdf342 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -40,12 +40,13 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "BLI_fileops.h" #include "BLI_ghash.h" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_string.h" -#include "BLI_utildefines.h" #include "DNA_genfile.h" #include "DNA_sdna_types.h" @@ -55,10 +56,10 @@ #include "BKE_library.h" // for free_main #include "BKE_idcode.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "readfile.h" diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index ac792a90735..1021d2a794d 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -100,6 +100,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_edgehash.h" @@ -140,7 +141,6 @@ #include "BKE_sequencer.h" #include "BKE_text.h" // for txt_extended_ascii_as_utf8 #include "BKE_tracking.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_sound.h" #include "IMB_imbuf.h" // for proxy / timecode versioning stuff @@ -149,6 +149,7 @@ #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "RE_engine.h" @@ -221,16 +222,6 @@ /* from misc_util: flip the bytes from x */ /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */ -// only used here in readfile.c -#define SWITCH_LONGINT(a) { \ - char s_i, *p_i; \ - p_i= (char *)&(a); \ - s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \ - s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \ - s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \ - s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; \ -} (void)0 - /***/ typedef struct OldNew { @@ -577,9 +568,9 @@ static void switch_endian_bh4(BHead4 *bhead) if ((bhead->code & 0xFFFF)==0) bhead->code >>= 16; if (bhead->code != ENDB) { - SWITCH_INT(bhead->len); - SWITCH_INT(bhead->SDNAnr); - SWITCH_INT(bhead->nr); + BLI_endian_switch_int32(&bhead->len); + BLI_endian_switch_int32(&bhead->SDNAnr); + BLI_endian_switch_int32(&bhead->nr); } } @@ -589,9 +580,9 @@ static void switch_endian_bh8(BHead8 *bhead) if ((bhead->code & 0xFFFF)==0) bhead->code >>= 16; if (bhead->code != ENDB) { - SWITCH_INT(bhead->len); - SWITCH_INT(bhead->SDNAnr); - SWITCH_INT(bhead->nr); + BLI_endian_switch_int32(&bhead->len); + BLI_endian_switch_int32(&bhead->SDNAnr); + BLI_endian_switch_int32(&bhead->nr); } } @@ -612,7 +603,7 @@ static void bh4_from_bh8(BHead *bhead, BHead8 *bhead8, int do_endian_swap) * 0x0000000000000000000012345678 would become 0x12345678000000000000000000000000 */ if (do_endian_swap) { - SWITCH_LONGINT(bhead8->old); + BLI_endian_switch_int64(&bhead8->old); } /* this patch is to avoid a long long being read from not-eight aligned positions @@ -1476,11 +1467,7 @@ static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */ static void test_pointer_array(FileData *fd, void **mat) { -#if defined(WIN32) && !defined(FREE_WINDOWS) - __int64 *lpoin, *lmat; -#else - long long *lpoin, *lmat; -#endif + int64_t *lpoin, *lmat; int *ipoin, *imat; size_t len; @@ -1497,7 +1484,7 @@ static void test_pointer_array(FileData *fd, void **mat) while (len-- > 0) { if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN)) - SWITCH_LONGINT(*lpoin); + BLI_endian_switch_int64(lpoin); *ipoin = (int)((*lpoin) >> 3); ipoin++; lpoin++; @@ -1567,16 +1554,13 @@ static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, FileData *f } else if (prop->subtype == IDP_DOUBLE) { if (switch_endian) { - for (i = 0; i < prop->len; i++) { - SWITCH_LONGINT(((double *)prop->data.pointer)[i]); - } + BLI_endian_switch_double_array(prop->data.pointer, prop->len); } } else { if (switch_endian) { - for (i = 0; i < prop->len; i++) { - SWITCH_INT(((int *)prop->data.pointer)[i]); - } + /* also used for floats */ + BLI_endian_switch_int32_array(prop->data.pointer, prop->len); } } } @@ -1628,9 +1612,9 @@ static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData */ if (switch_endian) { - SWITCH_INT(prop->data.val); - SWITCH_INT(prop->data.val2); - SWITCH_LONGINT(prop->data.val); + BLI_endian_switch_int32(&prop->data.val); + BLI_endian_switch_int32(&prop->data.val2); + BLI_endian_switch_int64((int64_t *)&prop->data.val); } break; @@ -1871,9 +1855,7 @@ static void direct_link_fmodifiers(FileData *fd, ListBase *list) data->coefficients = newdataadr(fd, data->coefficients); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - unsigned int a; - for (a = 0; a < data->arraysize; a++) - SWITCH_INT(data->coefficients[a]); + BLI_endian_switch_float_array(data->coefficients, data->arraysize); } } break; @@ -2777,11 +2759,8 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb) case IPO_BPOINT: case IPO_BEZTRIPLE: b = cp[0]; - - while (b--) { - SWITCH_INT((*poin)); - poin += 4; - } + BLI_endian_switch_float_array((float *)poin, b); + poin += sizeof(float) * b; break; } @@ -3072,19 +3051,11 @@ static void lib_link_curve(FileData *fd, Main *main) static void switch_endian_knots(Nurb *nu) { - int len; - if (nu->knotsu) { - len = KNOTSU(nu); - while (len--) { - SWITCH_INT(nu->knotsu[len]); - } + BLI_endian_switch_float_array(nu->knotsu, KNOTSU(nu)); } if (nu->knotsv) { - len = KNOTSV(nu); - while (len--) { - SWITCH_INT(nu->knotsv[len]); - } + BLI_endian_switch_float_array(nu->knotsv, KNOTSV(nu)); } } @@ -3302,11 +3273,10 @@ static void direct_link_pointcache(FileData *fd, PointCache *cache) /* the cache saves non-struct data without DNA */ if (pm->data[i] && ptcache_data_struct[i][0]=='\0' && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) { - int j, tot = (BKE_ptcache_data_size (i) * pm->totpoint)/4; /* data_size returns bytes */ + int tot = (BKE_ptcache_data_size (i) * pm->totpoint) / sizeof(int); /* data_size returns bytes */ int *poin = pm->data[i]; - for (j = 0; j < tot; j++) - SWITCH_INT(poin[j]); + BLI_endian_switch_int32_array(poin, tot); } } @@ -3775,12 +3745,7 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps)) { /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ /* this does swap for data written at write_mdisps() - readfile.c */ - int x; - float *tmpdisps = *mdisps[i].disps; - for (x = 0; x < mdisps[i].totdisp * 3; x++) { - SWITCH_INT(*tmpdisps); - tmpdisps++; - } + BLI_endian_switch_float_array(*mdisps[i].disps, mdisps[i].totdisp * 3); } if (!external && !mdisps[i].disps) mdisps[i].totdisp = 0; @@ -3950,11 +3915,8 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) TFace *tf = mesh->tface; int i; - for (i = 0; i < (mesh->totface); i++, tf++) { - SWITCH_INT(tf->col[0]); - SWITCH_INT(tf->col[1]); - SWITCH_INT(tf->col[2]); - SWITCH_INT(tf->col[3]); + for (i = 0; i < mesh->totface; i++, tf++) { + BLI_endian_switch_uint32_array(tf->col, 4); } } } @@ -4480,10 +4442,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) hmd->indexar = newdataadr(fd, hmd->indexar); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - for (a = 0; a < hmd->totindex; a++) { - SWITCH_INT(hmd->indexar[a]); - } + BLI_endian_switch_int32_array(hmd->indexar, hmd->totindex); } } else if (md->type == eModifierType_ParticleSystem) { @@ -4513,24 +4472,11 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) mmd->bindcos = newdataadr(fd, mmd->bindcos); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - - if (mmd->bindoffsets) - for (a=0; atotvert+1; a++) - SWITCH_INT(mmd->bindoffsets[a]); - if (mmd->bindcagecos) - for (a=0; atotcagevert*3; a++) - SWITCH_INT(mmd->bindcagecos[a]); - if (mmd->dynverts) - for (a=0; atotvert; a++) - SWITCH_INT(mmd->dynverts[a]); - - if (mmd->bindweights) - for (a=0; atotcagevert*mmd->totvert; a++) - SWITCH_INT(mmd->bindweights[a]); - if (mmd->bindcos) - for (a=0; atotcagevert*3; a++) - SWITCH_INT(mmd->bindcos[a]); + if (mmd->bindoffsets) BLI_endian_switch_int32_array(mmd->bindoffsets, mmd->totvert + 1); + if (mmd->bindcagecos) BLI_endian_switch_float_array(mmd->bindcagecos, mmd->totcagevert * 3); + if (mmd->dynverts) BLI_endian_switch_int32_array(mmd->dynverts, mmd->totvert); + if (mmd->bindweights) BLI_endian_switch_float_array(mmd->bindweights, mmd->totvert); + if (mmd->bindcos) BLI_endian_switch_float_array(mmd->bindcos, mmd->totcagevert * 3); } } else if (md->type == eModifierType_Ocean) { @@ -4724,10 +4670,7 @@ static void direct_link_object(FileData *fd, Object *ob) hook->indexar= newdataadr(fd, hook->indexar); if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) { - int a; - for (a = 0; a < hook->totindex; a++) { - SWITCH_INT(hook->indexar[a]); - } + BLI_endian_switch_int32_array(hook->indexar, hook->totindex); } /* Do conversion here because if we have loaded @@ -7086,8 +7029,8 @@ static void do_version_ntree_mask_264(void *UNUSED(data), ID *UNUSED(id), bNodeT if (node->storage == NULL) { NodeMask *data = MEM_callocN(sizeof(NodeMask), __func__); /* move settings into own struct */ - data->size_x = node->custom3; - data->size_y = node->custom4; + data->size_x = (int)node->custom3; + data->size_y = (int)node->custom4; node->custom3 = 0.5f; /* default shutter */ node->storage = data; } diff --git a/source/blender/blenloader/intern/runtime.c b/source/blender/blenloader/intern/runtime.c index a7dae22cda2..eaf725dda9e 100644 --- a/source/blender/blenloader/intern/runtime.c +++ b/source/blender/blenloader/intern/runtime.c @@ -50,7 +50,6 @@ #include "BKE_blender.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLI_blenlib.h" diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 1bad1bd80df..a4f190c8167 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -89,7 +89,6 @@ #include "BKE_screen.h" #include "BKE_sequencer.h" #include "BKE_texture.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_sound.h" #include "NOD_socket.h" diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 8ace277b42d..1cc0d4180ab 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -95,7 +95,6 @@ #include "BKE_property.h" // for get_ob_property #include "BKE_scene.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "IMB_imbuf.h" // for proxy / timecode versioning stuff diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 252e81537c4..f8b3a548345 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -154,7 +154,6 @@ Any case: direct data is ALWAYS after the lib block #include "BKE_report.h" #include "BKE_sequencer.h" #include "BKE_subsurf.h" -#include "BKE_utildefines.h" #include "BKE_modifier.h" #include "BKE_fcurve.h" #include "BKE_pointcache.h" @@ -163,6 +162,7 @@ Any case: direct data is ALWAYS after the lib block #include "BLO_writefile.h" #include "BLO_readfile.h" #include "BLO_undofile.h" +#include "BLO_blend_defs.h" #include "readfile.h" diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index 58ccfa79a02..c0439311104 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -527,9 +527,9 @@ void BM_active_face_set(BMesh *bm, BMFace *efa) bm->act_face = efa; } -BMFace *BM_active_face_get(BMesh *bm, int sloppy) +BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected) { - if (bm->act_face) { + if (bm->act_face && (!selected || BM_elem_flag_test(bm->act_face, BM_ELEM_SELECT))) { return bm->act_face; } else if (sloppy) { @@ -546,6 +546,9 @@ BMFace *BM_active_face_get(BMesh *bm, int sloppy) if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { f = NULL; } + else if (selected && !BM_elem_flag_test(f, BM_ELEM_SELECT)) { + f = NULL; + } else { break; } @@ -768,7 +771,7 @@ void BM_select_history_validate(BMesh *bm) int BM_select_history_active_get(BMesh *bm, BMEditSelection *ese) { BMEditSelection *ese_last = bm->selected.last; - BMFace *efa = BM_active_face_get(bm, FALSE); + BMFace *efa = BM_active_face_get(bm, FALSE, FALSE); ese->next = ese->prev = NULL; diff --git a/source/blender/bmesh/intern/bmesh_marking.h b/source/blender/bmesh/intern/bmesh_marking.h index 9b73ed2c390..8d4397794d5 100644 --- a/source/blender/bmesh/intern/bmesh_marking.h +++ b/source/blender/bmesh/intern/bmesh_marking.h @@ -71,7 +71,7 @@ int BM_mesh_elem_hflag_count_disabled(BMesh *bm, const char htype, const char hf /* edit selection stuff */ void BM_active_face_set(BMesh *bm, BMFace *f); -BMFace *BM_active_face_get(BMesh *bm, int sloppy); +BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected); void BM_editselection_center(BMEditSelection *ese, float r_center[3]); void BM_editselection_normal(BMEditSelection *ese, float r_normal[3]); diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 807570f0d86..1d056dbfae7 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -606,11 +606,11 @@ int BM_face_point_inside_test(BMFace *f, const float co[3]) do { float v1[2], v2[2]; - v1[0] = (l_iter->prev->v->co[ax] - cent[ax]) * onepluseps + cent[ax]; - v1[1] = (l_iter->prev->v->co[ay] - cent[ay]) * onepluseps + cent[ay]; + v1[0] = (l_iter->prev->v->co[ax] - cent[0]) * onepluseps + cent[0]; + v1[1] = (l_iter->prev->v->co[ay] - cent[1]) * onepluseps + cent[1]; - v2[0] = (l_iter->v->co[ax] - cent[ax]) * onepluseps + cent[ax]; - v2[1] = (l_iter->v->co[ay] - cent[ay]) * onepluseps + cent[ay]; + v2[0] = (l_iter->v->co[ax] - cent[0]) * onepluseps + cent[0]; + v2[1] = (l_iter->v->co[ay] - cent[1]) * onepluseps + cent[1]; crosses += linecrossesf(v1, v2, co2, out) != 0; } while ((l_iter = l_iter->next) != l_first); diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index 9ea8e631435..c8be7c9ce34 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -390,7 +390,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) if (!v1->e) BM_vert_kill(bm, v1); if (!v2->e) - BM_vert_kill(bm, v1); + BM_vert_kill(bm, v2); continue; } diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c index 3aa6e6dbe49..132d7050b31 100644 --- a/source/blender/bmesh/operators/bmo_inset.c +++ b/source/blender/bmesh/operators/bmo_inset.c @@ -283,7 +283,8 @@ void bmo_inset_exec(BMesh *bm, BMOperator *op) * cross product between both face normals */ add_v3_v3v3(tvec, e_info_a->no, e_info_b->no); - if ((f_a == f_b) || compare_v3v3(f_a->no, f_b->no, 0.00001f)) { + /* epsilon increased to fix [#32329] */ + if ((f_a == f_b) || compare_v3v3(f_a->no, f_b->no, 0.001f)) { normalize_v3(tvec); } else { diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c index 85beb6d092b..91527313972 100644 --- a/source/blender/bmesh/tools/BME_bevel.c +++ b/source/blender/bmesh/tools/BME_bevel.c @@ -38,7 +38,6 @@ #include "BLI_ghash.h" #include "BLI_memarena.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "BKE_bmesh.h" diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index d241926c20c..b2748a55b6a 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -683,12 +683,11 @@ void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId& listid for (unsigned int i = 0; i < fcu->totvert; i++) { double input_fov = fcu->bezt[i].vec[1][1]; - double xfov = (fov_type == CAMERA_YFOV) ? aspect * input_fov : input_fov; - // fov is in degrees, cam->lens is in millimiters - double fov = fov_to_focallength(DEG2RADF(input_fov), cam->sensor_x); + // NOTE: Needs more testing (As we curretnly have no official test data for this) + double xfov = (fov_type == CAMERA_YFOV) ? (2.0f * atanf(aspect * tanf(DEG2RADF(input_fov) * 0.5f))) : DEG2RADF(input_fov); - fcu->bezt[i].vec[1][1] = fov; + fcu->bezt[i].vec[1][1] = fov_to_focallength(xfov, cam->sensor_x); } BLI_addtail(AnimCurves, fcu); diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index c47798ee804..baaa6dbeed2 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -99,7 +99,6 @@ extern char build_rev[]; #include "BKE_action.h" // pose functions #include "BKE_armature.h" #include "BKE_image.h" -#include "BKE_utildefines.h" #include "BKE_object.h" #include "BLI_math.h" diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 60b03a211ba..f29933ea0c1 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -62,13 +62,13 @@ extern "C" { #include "BKE_texture.h" #include "BKE_fcurve.h" #include "BKE_depsgraph.h" -#include "BLI_path_util.h" #include "BKE_scene.h" #include "BKE_global.h" #include "BKE_material.h" -#include "BKE_utildefines.h" #include "BKE_image.h" +#include "BLI_path_util.h" + #include "DNA_camera_types.h" #include "DNA_lamp_types.h" @@ -867,9 +867,11 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) { double yfov = camera->getYFov().getValue(); double aspect = camera->getAspectRatio().getValue(); - double xfov = aspect * yfov; - // xfov is in degrees, cam->lens is in millimiters - cam->lens = fov_to_focallength(DEG2RADF(xfov), cam->sensor_x); + + // NOTE: Needs more testing (As we curretnly have no official test data for this) + + double xfov = 2.0f * atanf(aspect * tanf(DEG2RADF(yfov) * 0.5f)); + cam->lens = fov_to_focallength(xfov, cam->sensor_x); } break; } diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp index 66dcec7d8e4..ef714f2561f 100644 --- a/source/blender/collada/ImageExporter.cpp +++ b/source/blender/collada/ImageExporter.cpp @@ -39,7 +39,6 @@ extern "C" { #include "BKE_image.h" #include "BKE_main.h" #include "BKE_mesh.h" -#include "BKE_utildefines.h" #include "BLI_fileops.h" #include "BLI_path_util.h" #include "BLI_string.h" diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 5593fe993f4..cf211e2fbb1 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -570,7 +570,7 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me) if (loose_edge_count > 0) { unsigned int face_edge_count = me->totedge; - unsigned int total_edge_count = loose_edge_count + face_edge_count; + /* unsigned int total_edge_count = loose_edge_count + face_edge_count; */ /* UNUSED */ mesh_add_edges(me, loose_edge_count); MEdge *med = me->medge + face_edge_count; diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp index 5f133fe071f..f9af23faea8 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cpp +++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp @@ -54,6 +54,7 @@ static vector g_cpudevices; #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE /// @brief list of all thread for every CPUDevice in cpudevices a thread exists static ListBase g_cputhreads; +static bool g_cpuInitialized = false; /// @brief all scheduled work for the cpu static ThreadQueue *g_cpuqueue; static ThreadQueue *g_gpuqueue; @@ -67,11 +68,13 @@ static ListBase g_gputhreads; /// @brief all scheduled work for the gpu #ifdef COM_OPENCL_ENABLED static bool g_openclActive = false; +static bool g_openclInitialized = false; #endif #endif #endif #define MAX_HIGHLIGHT 8 +static bool g_highlightInitialized = false; extern "C" { int g_highlightIndex; void **g_highlightedNodes; @@ -255,40 +258,59 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t printf("OPENCL error: %s\n", errinfo); } -void WorkScheduler::initialize() +void WorkScheduler::initialize(bool use_opencl) { - if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead); - if (g_highlightedNodes) MEM_freeN(g_highlightedNodes); + /* initialize highlighting */ + if (!g_highlightInitialized) { + if (g_highlightedNodesRead) MEM_freeN(g_highlightedNodesRead); + if (g_highlightedNodes) MEM_freeN(g_highlightedNodes); - g_highlightedNodesRead = NULL; - g_highlightedNodes = NULL; + g_highlightedNodesRead = NULL; + g_highlightedNodes = NULL; - COM_startReadHighlights(); -#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE - int numberOfCPUThreads = BLI_system_thread_count(); + COM_startReadHighlights(); - for (int index = 0; index < numberOfCPUThreads; index++) { - CPUDevice *device = new CPUDevice(); - device->initialize(); - g_cpudevices.push_back(device); + g_highlightInitialized = true; } + +#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE + /* initialize CPU threads */ + if (!g_cpuInitialized) { + int numberOfCPUThreads = BLI_system_thread_count(); + + for (int index = 0; index < numberOfCPUThreads; index++) { + CPUDevice *device = new CPUDevice(); + device->initialize(); + g_cpudevices.push_back(device); + } + + g_cpuInitialized = true; + } + #ifdef COM_OPENCL_ENABLED - g_context = NULL; - g_program = NULL; - if (clCreateContextFromType) { - cl_uint numberOfPlatforms = 0; - cl_int error; - error = clGetPlatformIDs(0, 0, &numberOfPlatforms); - if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } - if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms); - cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__); - error = clGetPlatformIDs(numberOfPlatforms, platforms, 0); - unsigned int indexPlatform; - for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) { - cl_platform_id platform = platforms[indexPlatform]; - cl_uint numberOfDevices = 0; - clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices); - if (numberOfDevices > 0) { + /* deinitialize OpenCL GPU's */ + if (use_opencl && !g_openclInitialized) { + g_context = NULL; + g_program = NULL; + + OCL_init(); /* this will check and skip if already initialized */ + + if (clCreateContextFromType) { + cl_uint numberOfPlatforms = 0; + cl_int error; + error = clGetPlatformIDs(0, 0, &numberOfPlatforms); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms); + cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__); + error = clGetPlatformIDs(numberOfPlatforms, platforms, 0); + unsigned int indexPlatform; + for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) { + cl_platform_id platform = platforms[indexPlatform]; + cl_uint numberOfDevices = 0; + clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices); + if (numberOfDevices <= 0) + continue; + cl_device_id *cldevices = (cl_device_id *)MEM_mallocN(sizeof(cl_device_id) * numberOfDevices, __func__); clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices, 0); @@ -324,8 +346,10 @@ void WorkScheduler::initialize() } MEM_freeN(cldevices); } + MEM_freeN(platforms); } - MEM_freeN(platforms); + + g_openclInitialized = true; } #endif #endif @@ -334,37 +358,52 @@ void WorkScheduler::initialize() void WorkScheduler::deinitialize() { #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE - Device *device; - while (g_cpudevices.size() > 0) { - device = g_cpudevices.back(); - g_cpudevices.pop_back(); - device->deinitialize(); - delete device; + /* deinitialize CPU threads */ + if (g_cpuInitialized) { + Device *device; + while (g_cpudevices.size() > 0) { + device = g_cpudevices.back(); + g_cpudevices.pop_back(); + device->deinitialize(); + delete device; + } + + g_cpuInitialized = false; } + #ifdef COM_OPENCL_ENABLED - while (g_gpudevices.size() > 0) { - device = g_gpudevices.back(); - g_gpudevices.pop_back(); - device->deinitialize(); - delete device; - } - if (g_program) { - clReleaseProgram(g_program); - g_program = NULL; - } - if (g_context) { - clReleaseContext(g_context); - g_context = NULL; + /* deinitialize OpenCL GPU's */ + if (g_openclInitialized) { + Device *device; + while (g_gpudevices.size() > 0) { + device = g_gpudevices.back(); + g_gpudevices.pop_back(); + device->deinitialize(); + delete device; + } + if (g_program) { + clReleaseProgram(g_program); + g_program = NULL; + } + if (g_context) { + clReleaseContext(g_context); + g_context = NULL; + } + + g_openclInitialized = false; } #endif #endif - if (g_highlightedNodes) { - MEM_freeN(g_highlightedNodes); - } + /* deinitialize highlighting */ + if (g_highlightInitialized) { + if (g_highlightedNodes) + MEM_freeN(g_highlightedNodes); - if (g_highlightedNodesRead) { - MEM_freeN(g_highlightedNodesRead); + if (g_highlightedNodesRead) + MEM_freeN(g_highlightedNodesRead); + + g_highlightInitialized = false; } } diff --git a/source/blender/compositor/intern/COM_WorkScheduler.h b/source/blender/compositor/intern/COM_WorkScheduler.h index f56fe94201e..4ab23cf9ae4 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.h +++ b/source/blender/compositor/intern/COM_WorkScheduler.h @@ -74,8 +74,10 @@ public: * After mutex initialization the system is queried in order to count the number of CPUDevices and GPUDevices to be created. * For every hardware thread a CPUDevice and for every OpenCL GPU device a OpenCLDevice is created. * these devices are stored in a separate list (cpudevices & gpudevices) + * + * This function can be called multiple times to lazily initialize OpenCL. */ - static void initialize(); + static void initialize(bool use_opencl); /** * @brief deinitialize the WorkScheduler diff --git a/source/blender/compositor/intern/COM_compositor.cpp b/source/blender/compositor/intern/COM_compositor.cpp index 7dcb3572a14..daf48d65caf 100644 --- a/source/blender/compositor/intern/COM_compositor.cpp +++ b/source/blender/compositor/intern/COM_compositor.cpp @@ -36,24 +36,29 @@ extern "C" { static ThreadMutex s_compositorMutex; static char is_compositorMutex_init = FALSE; + void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) { - if (is_compositorMutex_init == FALSE) { /// TODO: move to blender startup phase - memset(&s_compositorMutex, 0, sizeof(s_compositorMutex)); + /* initialize mutex, TODO this mutex init is actually not thread safe and + * should be done somewhere as part of blender startup, all the other + * initializations can be done lazily */ + if (is_compositorMutex_init == FALSE) { BLI_mutex_init(&s_compositorMutex); - OCL_init(); - WorkScheduler::initialize(); ///TODO: call workscheduler.deinitialize somewhere is_compositorMutex_init = TRUE; } + BLI_mutex_lock(&s_compositorMutex); + if (editingtree->test_break(editingtree->tbh)) { // during editing multiple calls to this method can be triggered. // make sure one the last one will be doing the work. BLI_mutex_unlock(&s_compositorMutex); return; - } + /* initialize workscheduler, will check if already done. TODO deinitialize somewhere */ + bool use_opencl = (editingtree->flag & NTREE_COM_OPENCL); + WorkScheduler::initialize(use_opencl); /* set progress bar to 0% and status to init compositing */ editingtree->progress(editingtree->prh, 0.0); @@ -83,11 +88,12 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) void COM_deinitialize() { - if (is_compositorMutex_init) - { + if (is_compositorMutex_init) { BLI_mutex_lock(&s_compositorMutex); + deintializeDistortionCache(); WorkScheduler::deinitialize(); + is_compositorMutex_init = FALSE; BLI_mutex_unlock(&s_compositorMutex); BLI_mutex_end(&s_compositorMutex); diff --git a/source/blender/compositor/nodes/COM_MovieClipNode.cpp b/source/blender/compositor/nodes/COM_MovieClipNode.cpp index a250841b160..6d5b9bba8aa 100644 --- a/source/blender/compositor/nodes/COM_MovieClipNode.cpp +++ b/source/blender/compositor/nodes/COM_MovieClipNode.cpp @@ -49,10 +49,14 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex bNode *editorNode = this->getbNode(); MovieClip *movieClip = (MovieClip *)editorNode->id; MovieClipUser *movieClipUser = (MovieClipUser *)editorNode->storage; - + bool cacheFrame = !context->isRendering(); + ImBuf *ibuf = NULL; if (movieClip) { - ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser); + if (cacheFrame) + ibuf = BKE_movieclip_get_ibuf(movieClip, movieClipUser); + else + ibuf = BKE_movieclip_get_ibuf_flag(movieClip, movieClipUser, movieClip->flag, MOVIECLIP_CACHE_SKIP); } // always connect the output image @@ -78,10 +82,11 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex outputMovieClip->relinkConnections(operation->getOutputSocket()); } } + operation->setMovieClip(movieClip); operation->setMovieClipUser(movieClipUser); operation->setFramenumber(context->getFramenumber()); - operation->setCacheFrame(!context->isRendering()); + operation->setCacheFrame(cacheFrame); graph->addOperation(operation); MovieTrackingStabilization *stab = &movieClip->tracking.stabilization; diff --git a/source/blender/compositor/nodes/COM_OutputFileNode.cpp b/source/blender/compositor/nodes/COM_OutputFileNode.cpp index e85f521def0..b8cee29fee6 100644 --- a/source/blender/compositor/nodes/COM_OutputFileNode.cpp +++ b/source/blender/compositor/nodes/COM_OutputFileNode.cpp @@ -24,8 +24,8 @@ #include "COM_OutputFileNode.h" #include "COM_OutputFileOperation.h" #include "COM_ExecutionSystem.h" + #include "BLI_path_util.h" -#include "BKE_utildefines.h" OutputFileNode::OutputFileNode(bNode *editorNode) : Node(editorNode) { diff --git a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp index c37830a9d92..867053bf1d2 100644 --- a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp +++ b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp @@ -23,7 +23,6 @@ #include "COM_AntiAliasOperation.h" #include "BLI_math.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.cpp b/source/blender/compositor/operations/COM_MovieClipOperation.cpp index b73db74b061..709e4b7d4b0 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieClipOperation.cpp @@ -48,14 +48,10 @@ void MovieClipOperation::initExecution() BKE_movieclip_user_set_frame(this->m_movieClipUser, this->m_framenumber); ImBuf *ibuf; - if (this->m_cacheFrame) { + if (this->m_cacheFrame) ibuf = BKE_movieclip_get_ibuf(this->m_movieClip, this->m_movieClipUser); - } - else { - int flag = this->m_movieClip->flag & MCLIP_TIMECODE_FLAGS; - - ibuf = BKE_movieclip_get_ibuf_flag(this->m_movieClip, this->m_movieClipUser, flag, MOVIECLIP_CACHE_SKIP); - } + else + ibuf = BKE_movieclip_get_ibuf_flag(this->m_movieClip, this->m_movieClipUser, this->m_movieClip->flag, MOVIECLIP_CACHE_SKIP); if (ibuf) { this->m_movieClipBuffer = ibuf; diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 0d6e5bfa61a..532242c97ce 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -24,8 +24,9 @@ #ifndef _COM_OutputFileOperation_h #define _COM_OutputFileOperation_h #include "COM_NodeOperation.h" + #include "BLI_rect.h" -#include "BKE_utildefines.h" +#include "BLI_path_util.h" #include "intern/openexr/openexr_multi.h" diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 16168888573..86f729502bb 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -61,7 +61,6 @@ #include "BKE_curve.h" #include "BKE_key.h" #include "BKE_context.h" -#include "BKE_utildefines.h" /* FILE_MAX */ #include "UI_interface.h" #include "UI_interface_icons.h" diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c index 3255bc47148..6ce9fc638be 100644 --- a/source/blender/editors/animation/anim_deps.c +++ b/source/blender/editors/animation/anim_deps.c @@ -50,7 +50,6 @@ #include "BKE_global.h" #include "BKE_node.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "RNA_access.h" diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index a0acdd710e0..c92b7ce2761 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -89,7 +89,6 @@ #include "BKE_node.h" #include "BKE_mask.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "ED_anim_api.h" #include "ED_markers.h" diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 3883dce7671..b5c0555bf63 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -45,7 +45,6 @@ #include "BKE_fcurve.h" -#include "BKE_utildefines.h" #include "BKE_report.h" #include "BKE_library.h" #include "BKE_global.h" diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 35284b26d29..da440063552 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -135,7 +135,7 @@ struct UvElementMap *EDBM_uv_element_map_create(struct BMEditMesh *em, int selec void EDBM_uv_element_map_free(struct UvElementMap *vmap); int EDBM_mtexpoly_check(struct BMEditMesh *em); -struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy); +struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy, int selected); void EDBM_uv_vert_map_free(struct UvVertMap *vmap); struct UvMapVert *EDBM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index e668b6a39fa..2dbaa2998e3 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -527,7 +527,7 @@ enum { BUT_GET_TIP, BUT_GET_RNA_TIP, BUT_GET_RNAENUM_TIP, - BUT_GET_OP_KEYMAP, + BUT_GET_OP_KEYMAP }; typedef struct uiStringInfo { @@ -538,7 +538,7 @@ typedef struct uiStringInfo { /* Note: Expects pointers to uiStringInfo structs as parameters. * Will fill them with translated strings, when possible. * Strings in uiStringInfo must be MEM_freeN'ed by caller. */ -void uiButGetStrInfo(struct bContext *C, uiBut *but, const int nbr, ...); +void uiButGetStrInfo(struct bContext *C, uiBut *but, int nbr, ...); /* Edit i18n stuff. */ /* Name of the main py op from i18n addon. */ @@ -573,7 +573,7 @@ typedef void (*uiIDPoinFuncFP)(struct bContext *C, const char *str, struct ID ** typedef void (*uiIDPoinFunc)(struct bContext *C, struct ID *id, int event); uiBut *uiDefIDPoinBut(uiBlock *block, uiIDPoinFuncFP func, short blocktype, int retval, const char *str, - int x, int y, short width, short height, void *idpp, const char *tip); + int x, int y, short width, short height, void *idpp, const char *tip); int uiIconFromID(struct ID *id); @@ -624,7 +624,9 @@ void uiButSetNFunc(uiBut *but, uiButHandleNFunc func, void *argN, void void uiButSetCompleteFunc(uiBut *but, uiButCompleteFunc func, void *arg); -void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), void *arg1, void *arg2); +void uiBlockSetDrawExtraFunc(uiBlock *block, + void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), + void *arg1, void *arg2); void uiButSetFocusOnEnter(struct wmWindow *win, uiBut *but); diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 3a8f05a76f0..792c96fe7c8 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -203,7 +203,7 @@ void UI_view2d_operatortypes(void); void UI_view2d_keymap(struct wmKeyConfig *keyconf); void UI_view2d_smooth_view(struct bContext *C, struct ARegion *ar, - const struct rctf *cur); + const struct rctf *cur); #endif /* __UI_VIEW2D_H__ */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index afbabaaa8d7..ffce2b618a3 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -33,7 +33,8 @@ #include #include #include - +#include /* offsetof() */ + #include "MEM_guardedalloc.h" #include "DNA_scene_types.h" @@ -41,7 +42,12 @@ #include "DNA_userdef_types.h" #include "BLI_math.h" -#include "BLI_blenlib.h" +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_string_utf8.h" +#include "BLI_path_util.h" +#include "BLI_rect.h" + #include "BLI_dynstr.h" #include "BLI_utildefines.h" @@ -50,7 +56,6 @@ #include "BKE_unit.h" #include "BKE_screen.h" #include "BKE_idprop.h" -#include "BKE_utildefines.h" /* FILE_MAX */ #include "BIF_gl.h" @@ -1077,8 +1082,12 @@ static void ui_is_but_sel(uiBut *but, double *value) int lvalue; UI_GET_BUT_VALUE_INIT(but, *value); lvalue = (int)*value; - if (BTST(lvalue, (but->bitnr)) ) is_push = is_true; - else is_push = !is_true; + if (UI_BITBUT_TEST(lvalue, (but->bitnr))) { + is_push = is_true; + } + else { + is_push = !is_true; + } } else { switch (but->type) { diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index ca52daa8cd2..54b391bca6b 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -501,9 +501,9 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) lvalue = (int)value; if (but->bit) { - w = BTST(lvalue, but->bitnr); - if (w) lvalue = BCLR(lvalue, but->bitnr); - else lvalue = BSET(lvalue, but->bitnr); + w = UI_BITBUT_TEST(lvalue, but->bitnr); + if (w) lvalue = UI_BITBUT_CLR(lvalue, but->bitnr); + else lvalue = UI_BITBUT_SET(lvalue, but->bitnr); if (but->type == TOGR) { if (!data->togonly) { @@ -605,27 +605,27 @@ static void ui_apply_but_TOG3(bContext *C, uiBut *but, uiHandleButtonData *data) if (but->pointype == SHO) { short *sp = (short *)but->poin; - if (BTST(sp[1], but->bitnr)) { - sp[1] = BCLR(sp[1], but->bitnr); - sp[0] = BCLR(sp[0], but->bitnr); + if (UI_BITBUT_TEST(sp[1], but->bitnr)) { + sp[1] = UI_BITBUT_CLR(sp[1], but->bitnr); + sp[0] = UI_BITBUT_CLR(sp[0], but->bitnr); } - else if (BTST(sp[0], but->bitnr)) { - sp[1] = BSET(sp[1], but->bitnr); + else if (UI_BITBUT_TEST(sp[0], but->bitnr)) { + sp[1] = UI_BITBUT_SET(sp[1], but->bitnr); } else { - sp[0] = BSET(sp[0], but->bitnr); + sp[0] = UI_BITBUT_SET(sp[0], but->bitnr); } } else { - if (BTST(*(but->poin + 2), but->bitnr)) { - *(but->poin + 2) = BCLR(*(but->poin + 2), but->bitnr); - *(but->poin) = BCLR(*(but->poin), but->bitnr); + if (UI_BITBUT_TEST(*(but->poin + 2), but->bitnr)) { + *(but->poin + 2) = UI_BITBUT_CLR(*(but->poin + 2), but->bitnr); + *(but->poin) = UI_BITBUT_CLR(*(but->poin), but->bitnr); } - else if (BTST(*(but->poin), but->bitnr)) { - *(but->poin + 2) = BSET(*(but->poin + 2), but->bitnr); + else if (UI_BITBUT_TEST(*(but->poin), but->bitnr)) { + *(but->poin + 2) = UI_BITBUT_SET(*(but->poin + 2), but->bitnr); } else { - *(but->poin) = BSET(*(but->poin), but->bitnr); + *(but->poin) = UI_BITBUT_SET(*(but->poin), but->bitnr); } } @@ -1187,12 +1187,20 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, else if (mode == 'c') { ui_get_but_vectorf(but, rgb); + /* convert to linear color to do compatible copy between gamma and non-gamma */ + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) + srgb_to_linearrgb_v3_v3(rgb, rgb); + BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]); WM_clipboard_text_set(buf, 0); } else { if (sscanf(buf, "[%f, %f, %f]", &rgb[0], &rgb[1], &rgb[2]) == 3) { + /* assume linear colors in buffer */ + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) + linearrgb_to_srgb_v3_v3(rgb, rgb); + button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); ui_set_but_vectorf(but, rgb); button_activate_state(C, but, BUTTON_STATE_EXIT); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index dd3c2e491a7..1871f3c8336 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -59,7 +59,6 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_icons.h" -#include "BKE_utildefines.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 567109e26d0..d39fbbf7e61 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -131,6 +131,14 @@ typedef enum { /* for scope resize zone */ #define SCOPE_RESIZE_PAD 9 +/* bit button defines */ +/* Bit operations */ +#define UI_BITBUT_TEST(a, b) ( ( (a) & 1 << (b) ) != 0) +#define UI_BITBUT_SET(a, b) ( (a) | 1 << (b) ) +#define UI_BITBUT_CLR(a, b) ( (a) & ~(1 << (b)) ) +/* bit-row */ +#define UI_BITBUT_ROW(min, max) (((max) >= 31 ? 0xFFFFFFFF : (1 << (max + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) ) + typedef struct uiLinkLine { /* only for draw/edit */ struct uiLinkLine *next, *prev; struct uiBut *from, *to; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 96c1b00d46d..301aea896bc 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -2021,27 +2021,20 @@ static void picker_new_hide_reveal(uiBlock *block, short colormode) /* tag buttons */ for (bt = block->buttons.first; bt; bt = bt->next) { - - if (bt->type == LABEL) { - if (bt->str[1] == 'G') { - if (colormode == 2) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } + if (bt->func == do_picker_rna_cb && bt->type == NUMSLI) { + /* RGB sliders (color circle is always shown) */ + if (colormode == 0) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; } - - if (bt->type == NUMSLI || bt->type == TEX) { - if (bt->str[1] == 'e') { - if (colormode == 2) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } - else if (ELEM3(bt->str[0], 'R', 'G', 'B')) { - if (colormode == 0) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } - else if (ELEM3(bt->str[0], 'H', 'S', 'V')) { - if (colormode == 1) bt->flag &= ~UI_HIDDEN; - else bt->flag |= UI_HIDDEN; - } + else if (bt->func == do_hsv_rna_cb) { + /* HSV sliders */ + if (colormode == 1) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; + } + else if (bt->func == do_hex_rna_cb || bt->type == LABEL) { + /* hex input or gamma correction status label */ + if (colormode == 2) bt->flag &= ~UI_HIDDEN; + else bt->flag |= UI_HIDDEN; } } } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index ee0613ea0d0..b16250021d3 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -257,7 +257,7 @@ uiStyle *UI_GetStyle(void) { uiStyle *style = NULL; /* offset is two struct uiStyle pointers */ - /* style = BLI_findstring( &U.uistyles, "Unifont Style", sizeof(style)*2 ) */; + /* style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2) */; return (style != NULL) ? style : U.uistyles.first; } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 7e0fe4d277e..9aaafe28377 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2581,6 +2581,7 @@ void uiTemplateOperatorSearch(uiLayout *layout) #define B_STOPCOMPO 4 #define B_STOPSEQ 5 #define B_STOPCLIP 6 +#define B_STOPOTHER 7 static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) { @@ -2603,6 +2604,9 @@ static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) case B_STOPCLIP: WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL); break; + case B_STOPOTHER: + G.is_break = TRUE; + break; } } @@ -2642,6 +2646,10 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) handle_event = B_STOPCOMPO; break; } + else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) { + handle_event = B_STOPOTHER; + break; + } } owner = scene; } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ef8d8302fa7..9131c2744cd 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -46,7 +46,6 @@ #include "BKE_context.h" #include "BKE_curve.h" -#include "BKE_utildefines.h" #include "RNA_access.h" @@ -1257,9 +1256,9 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB if (but->type == BUT_TOGDUAL) { int dualset = 0; if (but->pointype == SHO) - dualset = BTST(*(((short *)but->poin) + 1), but->bitnr); + dualset = UI_BITBUT_TEST(*(((short *)but->poin) + 1), but->bitnr); else if (but->pointype == INT) - dualset = BTST(*(((int *)but->poin) + 1), but->bitnr); + dualset = UI_BITBUT_TEST(*(((int *)but->poin) + 1), but->bitnr); widget_draw_icon(but, ICON_DOT, dualset ? 1.0f : 0.25f, rect); } diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 229bbdbefb7..8f08c3afc36 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -160,7 +160,7 @@ typedef struct KnifeTool_OpData { int totlinehit; /* Data for mouse-position-derived data (cur) and previous click (prev) */ - KnifePosData cur, prev; + KnifePosData curr, prev; int totkedge, totkvert; @@ -290,7 +290,7 @@ static void knife_add_edge_faces_to_vert(KnifeTool_OpData *kcd, KnifeVert *kfv, } /* Find a face in common in the two faces lists. - If more than one, return the first; if none, return NULL */ + * If more than one, return the first; if none, return NULL */ static BMFace *knife_find_common_face(ListBase *faces1, ListBase *faces2) { Ref *ref1, *ref2; @@ -368,22 +368,22 @@ static KnifeEdge *get_bm_knife_edge(KnifeTool_OpData *kcd, BMEdge *e) * Copy the current position data into prev. */ static void knife_start_cut(KnifeTool_OpData *kcd) { - kcd->prev = kcd->cur; - kcd->cur.is_space = 0; /*TODO: why do we do this? */ + kcd->prev = kcd->curr; + kcd->curr.is_space = 0; /*TODO: why do we do this? */ if (kcd->prev.vert == NULL && kcd->prev.edge == NULL && is_zero_v3(kcd->prev.cage)) { /* Make prevcage a point on the view ray to mouse closest to a point on model: choose vertex 0 */ float origin[3], ray[3], co[3]; BMVert *v0; - knife_input_ray_cast(kcd, kcd->cur.mval, origin, ray); + knife_input_ray_cast(kcd, kcd->curr.mval, origin, ray); add_v3_v3v3(co, origin, ray); v0 = BM_vert_at_index(kcd->em->bm, 0); if (v0) { closest_to_line_v3(kcd->prev.cage, v0->co, co, origin); copy_v3_v3(kcd->prev.co, kcd->prev.cage); /*TODO: do we need this? */ - copy_v3_v3(kcd->cur.cage, kcd->prev.cage); - copy_v3_v3(kcd->cur.co, kcd->prev.co); + copy_v3_v3(kcd->curr.cage, kcd->prev.cage); + copy_v3_v3(kcd->curr.co, kcd->prev.co); } } } @@ -471,15 +471,15 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, KnifeEdge *kfe, float return newkfe->v2; } -/* Make a single KnifeEdge for cut from kcd->prev to kcd->cur. +/* Make a single KnifeEdge for cut from kcd->prev to kcd->curr. * and move cur data to prev. */ static void knife_add_single_cut(KnifeTool_OpData *kcd) { KnifeEdge *kfe = new_knife_edge(kcd), *kfe2 = NULL, *kfe3 = NULL; - if (kcd->prev.vert && kcd->prev.vert == kcd->cur.vert) + if (kcd->prev.vert && kcd->prev.vert == kcd->curr.vert) return; - if (kcd->prev.edge && kcd->prev.edge == kcd->cur.edge) + if (kcd->prev.edge && kcd->prev.edge == kcd->curr.edge) return; kfe->draw = 1; @@ -500,25 +500,25 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) knife_append_list(kcd, &kfe->v1->faces, kcd->prev.bmface); } - if (kcd->cur.vert) { - kfe->v2 = kcd->cur.vert; + if (kcd->curr.vert) { + kfe->v2 = kcd->curr.vert; } - else if (kcd->cur.edge) { - kfe->v2 = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); - kcd->cur.vert = kfe->v2; + else if (kcd->curr.edge) { + kfe->v2 = knife_split_edge(kcd, kcd->curr.edge, kcd->curr.co, &kfe3); + kcd->curr.vert = kfe->v2; } else { - kfe->v2 = new_knife_vert(kcd, kcd->cur.co, kcd->cur.co); - kfe->v2->draw = !kcd->cur.is_space; + kfe->v2 = new_knife_vert(kcd, kcd->curr.co, kcd->curr.co); + kfe->v2->draw = !kcd->curr.is_space; kfe->v2->isface = 1; - kfe->v2->inspace = kcd->cur.is_space; - if (kfe->v2->draw && kcd->cur.bmface) - knife_append_list(kcd, &kfe->v2->faces, kcd->cur.bmface); + kfe->v2->inspace = kcd->curr.is_space; + if (kfe->v2->draw && kcd->curr.bmface) + knife_append_list(kcd, &kfe->v2->faces, kcd->curr.bmface); - if (kcd->cur.is_space) + if (kcd->curr.is_space) kfe->draw = 0; - kcd->cur.vert = kfe->v2; + kcd->curr.vert = kfe->v2; } knife_find_basef(kfe); @@ -529,12 +529,12 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) knife_edge_append_face(kcd, kfe, kfe->basef); /* sanity check to make sure we're in the right edge/face lists */ - if (kcd->cur.bmface) { - if (!find_ref(&kfe->faces, kcd->cur.bmface)) { - knife_edge_append_face(kcd, kfe, kcd->cur.bmface); + if (kcd->curr.bmface) { + if (!find_ref(&kfe->faces, kcd->curr.bmface)) { + knife_edge_append_face(kcd, kfe, kcd->curr.bmface); } - if (kcd->prev.bmface && kcd->prev.bmface != kcd->cur.bmface) { + if (kcd->prev.bmface && kcd->prev.bmface != kcd->curr.bmface) { if (!find_ref(&kfe->faces, kcd->prev.bmface)) { knife_edge_append_face(kcd, kfe, kcd->prev.bmface); } @@ -542,7 +542,7 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) } /* set up for next cut */ - kcd->prev = kcd->cur; + kcd->prev = kcd->curr; } static int verge_linehit(const void *vlh1, const void *vlh2) @@ -554,6 +554,64 @@ static int verge_linehit(const void *vlh1, const void *vlh2) else return 0; } +/* If there's a linehit connected (same face) as testi in range [firsti, lasti], return the first such, else -1. + * If testi is out of range, look for connection to f instead, if f is non-NULL */ +static int find_connected_linehit(KnifeTool_OpData *kcd, int testi, BMFace *f, int firsti, int lasti) +{ + int i; + + for (i = firsti; i <= lasti; i++) { + if (testi >= 0 && testi < kcd->totlinehit) { + if (knife_find_common_face(&kcd->linehits[testi].kfe->faces, + &kcd->linehits[i].kfe->faces)) + return i; + } else if (f) { + if (find_ref(&kcd->linehits[i].kfe->faces, f)) + return i; + } + } + return -1; +} + +/* Sort in order of distance along cut line, but take care when distances are equal */ +static void knife_sort_linehits(KnifeTool_OpData *kcd) +{ + int i, j, k, nexti, nsame; + + qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); + + /* for ranges of equal "l", swap if neccesary to make predecessor and + * successor faces connected to the linehits at either end of the range */ + for (i = 0; i < kcd->totlinehit -1; i = nexti) { + for (j = i + 1; j < kcd->totlinehit; j++) { + if (fabsf(kcd->linehits[j].l - kcd->linehits[i].l) > 80*FLT_EPSILON) + break; + } + nexti = j; + j--; + nsame = j - i; + if (nsame > 0) { + /* find something connected to predecessor of equal range */ + k = find_connected_linehit(kcd, i - 1, kcd->prev.bmface, i, j); + if (k != -1) { + if (k != i) { + SWAP(BMEdgeHit, kcd->linehits[i], kcd->linehits[k]); + } + i++; + nsame--; + } + if (nsame > 0) { + /* find something connected to successor of equal range */ + k = find_connected_linehit(kcd, j + 1, kcd->curr.bmface, i, j); + if (k != -1 && k != j) { + SWAP(BMEdgeHit, kcd->linehits[j], kcd->linehits[k]); + } + } + /* rest of same range doesn't matter because we won't connect them */ + } + } +} + static void knife_add_single_cut_through(KnifeTool_OpData *kcd, KnifeVert *v1, KnifeVert *v2, BMFace *f) { KnifeEdge *kfenew; @@ -618,29 +676,30 @@ static void knife_cut_through(KnifeTool_OpData *kcd) return; } + /* TODO: probably don't need to sort at all */ qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); splitkfe = MEM_callocN(kcd->totlinehit * sizeof(KnifeEdge *), "knife_cut_through"); if (kcd->prev.vert) { - if (kcd->prev.vert == kcd->cur.vert) + if (kcd->prev.vert == kcd->curr.vert) return; firstv = kcd->prev.vert; knife_get_vert_faces(kcd, firstv, kcd->prev.bmface, &firstfaces); } else if (kcd->prev.edge) { - if (kcd->prev.edge == kcd->cur.edge) + if (kcd->prev.edge == kcd->curr.edge) return; firstv = knife_split_edge(kcd, kcd->prev.edge, kcd->prev.co, &kfe3); knife_get_edge_faces(kcd, kcd->prev.edge, &firstfaces); } - if (kcd->cur.vert) { - lastv = kcd->cur.vert; - knife_get_vert_faces(kcd, lastv, kcd->cur.bmface, &lastfaces); + if (kcd->curr.vert) { + lastv = kcd->curr.vert; + knife_get_vert_faces(kcd, lastv, kcd->curr.bmface, &lastfaces); } - else if (kcd->cur.edge) { - lastv = knife_split_edge(kcd, kcd->cur.edge, kcd->cur.co, &kfe3); - knife_get_edge_faces(kcd, kcd->cur.edge, &lastfaces); + else if (kcd->curr.edge) { + lastv = knife_split_edge(kcd, kcd->curr.edge, kcd->curr.co, &kfe3); + knife_get_edge_faces(kcd, kcd->curr.edge, &lastfaces); } if (firstv) { @@ -709,15 +768,15 @@ static void knife_cut_through(KnifeTool_OpData *kcd) kcd->totlinehit = 0; /* set up for next cut */ - kcd->prev = kcd->cur; + kcd->prev = kcd->curr; } /* User has just left-clicked after the first time. - * Add all knife cuts implied by line from prev to cur. + * Add all knife cuts implied by line from prev to curr. * If that line crossed edges then kcd->linehits will be non-NULL. */ static void knife_add_cut(KnifeTool_OpData *kcd) { - KnifePosData savcur = kcd->cur; + KnifePosData savcur = kcd->curr; if (kcd->cut_through) { knife_cut_through(kcd); @@ -726,8 +785,7 @@ static void knife_add_cut(KnifeTool_OpData *kcd) BMEdgeHit *lh, *lastlh, *firstlh; int i; - /* TODO: not a stable sort! need to figure out what to do for equal lambdas */ - qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); + knife_sort_linehits(kcd); lh = kcd->linehits; lastlh = firstlh = NULL; @@ -755,7 +813,11 @@ static void knife_add_cut(KnifeTool_OpData *kcd) if (len_v3v3(kcd->prev.cage, lh->realhit) < FLT_EPSILON * 80) continue; - if (len_v3v3(kcd->cur.cage, lh->realhit) < FLT_EPSILON * 80) + if (len_v3v3(kcd->curr.cage, lh->realhit) < FLT_EPSILON * 80) + continue; + + /* first linehit may be down face parallel to view */ + if (!lastlh && fabsf(lh->l) < FLT_EPSILON * 80) continue; if (kcd->prev.is_space) { @@ -768,12 +830,18 @@ static void knife_add_cut(KnifeTool_OpData *kcd) continue; } - kcd->cur.is_space = 0; - kcd->cur.edge = lh->kfe; - kcd->cur.bmface = lh->f; - kcd->cur.vert = lh->v; - copy_v3_v3(kcd->cur.co, lh->hit); - copy_v3_v3(kcd->cur.cage, lh->cagehit); + kcd->curr.is_space = 0; + kcd->curr.edge = lh->kfe; + kcd->curr.bmface = lh->f; + kcd->curr.vert = lh->v; + copy_v3_v3(kcd->curr.co, lh->hit); + copy_v3_v3(kcd->curr.cage, lh->cagehit); + + /* don't draw edges down faces parallel to view */ + if (lastlh && fabsf(lastlh->l - lh->l) < FLT_EPSILON * 80) { + kcd->prev = kcd->curr; + continue; + } knife_add_single_cut(kcd); } @@ -782,7 +850,7 @@ static void knife_add_cut(KnifeTool_OpData *kcd) kcd->prev = savcur; } else { - kcd->cur = savcur; + kcd->curr = savcur; knife_add_single_cut(kcd); } @@ -935,38 +1003,38 @@ static void knifetool_draw(const bContext *C, ARegion *UNUSED(ar), void *arg) glBegin(GL_LINES); glVertex3fv(kcd->prev.cage); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); glLineWidth(1.0); } - if (kcd->cur.edge) { + if (kcd->curr.edge) { glColor3ubv(kcd->colors.edge); glLineWidth(2.0); glBegin(GL_LINES); - glVertex3fv(kcd->cur.edge->v1->cageco); - glVertex3fv(kcd->cur.edge->v2->cageco); + glVertex3fv(kcd->curr.edge->v1->cageco); + glVertex3fv(kcd->curr.edge->v2->cageco); glEnd(); glLineWidth(1.0); } - else if (kcd->cur.vert) { + else if (kcd->curr.vert) { glColor3ubv(kcd->colors.point); glPointSize(11); glBegin(GL_POINTS); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); } - if (kcd->cur.bmface) { + if (kcd->curr.bmface) { glColor3ubv(kcd->colors.curpoint); glPointSize(9); glBegin(GL_POINTS); - glVertex3fv(kcd->cur.cage); + glVertex3fv(kcd->curr.cage); glEnd(); } @@ -1113,7 +1181,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, KnifeEdge *kfe = ref->ref; if (BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { - continue; // We already found a hit on this knife edge + continue; /* We already found a hit on this knife edge */ } if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, NULL)) { @@ -1121,13 +1189,17 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda); - if (kcd->cur.vert && len_squared_v3v3(kcd->cur.vert->cageco, p) < depsilon_squared) + if (kcd->curr.vert && len_squared_v3v3(kcd->curr.vert->cageco, p) < depsilon_squared) { continue; - if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) + } + if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) { continue; + } if (len_squared_v3v3(kcd->prev.cage, p) < depsilon_squared || - len_squared_v3v3(kcd->cur.cage, p) < depsilon_squared) + len_squared_v3v3(kcd->curr.cage, p) < depsilon_squared) + { continue; + } knife_project_v3(kcd, p, sp); view3d_unproject(mats, view, sp[0], sp[1], 0.0f); @@ -1135,15 +1207,17 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, if (kcd->cut_through) { hitf = FALSE; - } else { + } + else { /* check if this point is visible in the viewport */ float p1[3], lambda1; /* if face isn't planer, p may be behind the current tesselated tri, - so move it onto that and then a little towards eye */ + * so move it onto that and then a little towards eye */ if (isect_line_tri_v3(p, view, ls[0]->v->co, ls[1]->v->co, ls[2]->v->co, &lambda1, NULL)) { interp_v3_v3v3(p1, p, view, lambda1); - } else { + } + else { copy_v3_v3(p1, p); } sub_v3_v3(view, p1); @@ -1163,9 +1237,11 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { BMEdgeHit hit; - if (len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || + if (len_squared_v3v3(p, kcd->curr.co) < depsilon_squared || len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) + { continue; + } hit.kfe = kfe; hit.v = NULL; @@ -1185,15 +1261,18 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, /* select the closest from the edge endpoints or the midpoint */ if (perc < 0.25f) { perc = 0.0f; - } else if (perc < 0.75f) { + } + else if (perc < 0.75f) { perc = 0.5f; - } else { + } + else { perc = 1.0f; } interp_v3_v3v3(hit.hit, kfe->v1->co, kfe->v2->co, perc); interp_v3_v3v3(hit.cagehit, kfe->v1->cageco, kfe->v2->cageco, perc); - } else { + } + else { copy_v3_v3(hit.hit, p); } knife_project_v3(kcd, hit.cagehit, hit.schit); @@ -1239,7 +1318,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) } copy_v3_v3(v1, kcd->prev.cage); - copy_v3_v3(v2, kcd->cur.cage); + copy_v3_v3(v2, kcd->curr.cage); /* project screen line's 3d coordinates back into 2d */ knife_project_v3(kcd, v1, s1); @@ -1435,7 +1514,7 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo copy_v3_v3(p, co); copy_v3_v3(cagep, cageco); - kcd->cur.bmface = f; + kcd->curr.bmface = f; if (f) { KnifeEdge *cure = NULL; @@ -1499,8 +1578,8 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo /* update mouse coordinates to the snapped-to edge's screen coordinates * this is important for angle snap, which uses the previous mouse position */ edgesnap = new_knife_vert(kcd, p, cagep); - kcd->cur.mval[0] = (int)edgesnap->sco[0]; - kcd->cur.mval[1] = (int)edgesnap->sco[1]; + kcd->curr.mval[0] = (int)edgesnap->sco[0]; + kcd->curr.mval[1] = (int)edgesnap->sco[1]; } else { @@ -1532,7 +1611,7 @@ static KnifeVert *knife_find_closest_vert(KnifeTool_OpData *kcd, float p[3], flo /* set p to co, in case we don't find anything, means a face cut */ copy_v3_v3(p, co); copy_v3_v3(cagep, p); - kcd->cur.bmface = f; + kcd->curr.bmface = f; if (f) { ListBase *lst; @@ -1583,8 +1662,8 @@ static KnifeVert *knife_find_closest_vert(KnifeTool_OpData *kcd, float p[3], flo /* update mouse coordinates to the snapped-to vertex's screen coordinates * this is important for angle snap, which uses the previous mouse position */ - kcd->cur.mval[0] = (int)curv->sco[0]; - kcd->cur.mval[1] = (int)curv->sco[1]; + kcd->curr.mval[0] = (int)curv->sco[0]; + kcd->curr.mval[1] = (int)curv->sco[1]; } return curv; @@ -1641,30 +1720,30 @@ static int knife_update_active(KnifeTool_OpData *kcd) if (kcd->angle_snapping != ANGLE_FREE && kcd->mode == MODE_DRAGGING) knife_snap_angle(kcd); - knife_pos_data_clear(&kcd->cur); - kcd->cur.mval[0] = kcd->vc.mval[0]; - kcd->cur.mval[1] = kcd->vc.mval[1]; + knife_pos_data_clear(&kcd->curr); + kcd->curr.mval[0] = kcd->vc.mval[0]; + kcd->curr.mval[1] = kcd->vc.mval[1]; /* XXX knife_snap_angle updates the view coordinate mouse values to constrained angles, * which current mouse values are set to current mouse values are then used * for vertex and edge snap detection, without regard to the exact angle constraint */ - kcd->cur.vert = knife_find_closest_vert(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); + kcd->curr.vert = knife_find_closest_vert(kcd, kcd->curr.co, kcd->curr.cage, &kcd->curr.bmface, &kcd->curr.is_space); - if (!kcd->cur.vert) { - kcd->cur.edge = knife_find_closest_edge(kcd, kcd->cur.co, kcd->cur.cage, &kcd->cur.bmface, &kcd->cur.is_space); + if (!kcd->curr.vert) { + kcd->curr.edge = knife_find_closest_edge(kcd, kcd->curr.co, kcd->curr.cage, &kcd->curr.bmface, &kcd->curr.is_space); } /* if no hits are found this would normally default to (0, 0, 0) so instead * get a point at the mouse ray closest to the previous point. * Note that drawing lines in `free-space` isn't properly supported * but theres no guarantee (0, 0, 0) has any geometry either - campbell */ - if (kcd->cur.vert == NULL && kcd->cur.edge == NULL) { + if (kcd->curr.vert == NULL && kcd->curr.edge == NULL) { float origin[3], ray[3], co[3]; knife_input_ray_cast(kcd, kcd->vc.mval, origin, ray); add_v3_v3v3(co, origin, ray); - closest_to_line_v3(kcd->cur.cage, kcd->prev.cage, co, origin); + closest_to_line_v3(kcd->curr.cage, kcd->prev.cage, co, origin); } if (kcd->mode == MODE_DRAGGING) { @@ -2872,7 +2951,7 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) /* can't usefully select resulting edges in face mode */ kcd->select_result = (kcd->em->selectmode != SCE_SELECT_FACE); - knife_pos_data_clear(&kcd->cur); + knife_pos_data_clear(&kcd->curr); knife_pos_data_clear(&kcd->prev); knife_init_colors(&kcd->colors); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 765091a3d1d..a9e8c253c82 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -2221,7 +2221,7 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed, } } else if (em->selectmode & SCE_SELECT_FACE) { - f = BM_active_face_get(em->bm, TRUE); + f = BM_active_face_get(em->bm, TRUE, FALSE); if (f) { *r_efa = f; return; diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 6b7409cd031..a111c2ffafb 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -580,6 +580,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *em_v, void *UNUSED(obdata)) *em = *em_tmp; em->selectmode = um->selectmode; + bm->selectmode = um->selectmode; em->ob = ob; MEM_freeN(em_tmp); @@ -991,15 +992,15 @@ void EDBM_uv_element_map_free(UvElementMap *element_map) /* last_sel, use em->act_face otherwise get the last selected face in the editselections * at the moment, last_sel is mainly useful for making sure the space image dosnt flicker */ -MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy) +MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy, int selected) { BMFace *efa = NULL; if (!EDBM_mtexpoly_check(em)) return NULL; - efa = BM_active_face_get(em->bm, sloppy); - + efa = BM_active_face_get(em->bm, sloppy, selected); + if (efa) { if (r_act_efa) *r_act_efa = efa; return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 19ca30b9c45..09d89a961e4 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -43,10 +43,10 @@ #include "DNA_view3d_types.h" #include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "BLI_array.h" #include "BLI_math.h" #include "BLI_edgehash.h" -#include "BLI_utildefines.h" #include "BKE_context.h" #include "BKE_depsgraph.h" diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c index 14d20d68455..88b1f191e3a 100644 --- a/source/blender/editors/mesh/mesh_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -491,7 +491,7 @@ static int navmesh_face_copy_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); /* do work here */ - BMFace *efa_act = BM_active_face_get(em->bm, FALSE); + BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); if (efa_act) { if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) { diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index c4616fc39c6..b13a299c4c7 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1682,6 +1682,10 @@ void ED_vgroup_mirror(Object *ob, const short mirror_weights, const short flip_v } } + /* flip active group index */ + if (flip_vgroups && flip_map[def_nr] >= 0) + ob->actdef = flip_map[def_nr] + 1; + cleanup: if (flip_map) MEM_freeN(flip_map); @@ -1782,6 +1786,21 @@ static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg) if (ob->actdef < 1 && ob->defbase.first) ob->actdef = 1; + /* remove all dverts */ + if (ob->defbase.first == NULL) { + if (ob->type == OB_MESH) { + Mesh *me = ob->data; + CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert); + me->dvert = NULL; + } + else if (ob->type == OB_LATTICE) { + Lattice *lt = ob->data; + if (lt->dvert) { + MEM_freeN(lt->dvert); + lt->dvert = NULL; + } + } + } } /* only in editmode */ @@ -2674,7 +2693,7 @@ void OBJECT_OT_vertex_group_mirror(wmOperatorType *ot) /* properties */ RNA_def_boolean(ot->srna, "mirror_weights", TRUE, "Mirror Weights", "Mirror weights"); - RNA_def_boolean(ot->srna, "flip_group_names", TRUE, "Flip Groups", "Flip vertex group names"); + RNA_def_boolean(ot->srna, "flip_group_names", TRUE, "Flip Group Names", "Flip vertex group names"); RNA_def_boolean(ot->srna, "all_groups", FALSE, "All Groups", "Mirror all vertex groups weights"); } diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 35db9658f39..b05766d3201 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5339,12 +5339,25 @@ static void toggle_paint_cursor(bContext *C, int enable) * ensure that the cursor is hidden when not in paint mode */ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings) { + wmWindow *win; + ScrArea *sa; ImagePaintSettings *imapaint = &settings->imapaint; + int enabled = FALSE; - if (!imapaint->paintcursor) { - imapaint->paintcursor = - WM_paint_cursor_activate(wm, image_paint_poll, - brush_drawcursor, NULL); + for (win = wm->windows.first; win; win = win->next) + for (sa = win->screen->areabase.first; sa; sa = sa->next) + if (sa->spacetype == SPACE_IMAGE) + if (((SpaceImage*)sa->spacedata.first)->mode == SI_MODE_PAINT) + enabled = TRUE; + + if (enabled) { + BKE_paint_init(&imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT); + + if (!imapaint->paintcursor) { + imapaint->paintcursor = + WM_paint_cursor_activate(wm, image_paint_poll, + brush_drawcursor, NULL); + } } } diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 104f727c603..cc71be4938e 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -584,19 +584,21 @@ static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *p RCFlags flags) { wmKeyMapItem *kmi; + /* only size needs to follow zoom, strength shows fixed size circle */ + int flags_nozoom = flags & (~RC_ZOOM); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0); set_brush_rc_props(kmi->ptr, paint, "size", "use_unified_size", flags); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0); - set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags); + set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags_nozoom); kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", WKEY, KM_PRESS, 0, 0); - set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags); + set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags_nozoom); if (flags & RC_ROTATION) { kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0); - set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags); + set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags_nozoom); } } diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index d232a86f9e5..cff1f987da6 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -392,11 +392,12 @@ static void image_refresh(const bContext *C, ScrArea *sa) else if (obedit && obedit->type == OB_MESH) { Mesh *me = (Mesh *)obedit->data; struct BMEditMesh *em = me->edit_btmesh; - int sloppy = 1; /* partially selected face is ok */ + int sloppy = TRUE; /* partially selected face is ok */ + int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */ if (BKE_scene_use_new_shading_nodes(scene)) { /* new shading system, get image from material */ - BMFace *efa = BM_active_face_get(em->bm, sloppy); + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) { Image *node_ima; @@ -413,8 +414,8 @@ static void image_refresh(const bContext *C, ScrArea *sa) if (em && EDBM_mtexpoly_check(em)) { sima->image = NULL; - tf = EDBM_mtexpoly_active_get(em, NULL, TRUE); /* partially selected face is ok */ - + tf = EDBM_mtexpoly_active_get(em, NULL, sloppy, selected); + if (tf) { /* don't need to check for pin here, see above */ sima->image = tf->tpage; diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index a05bc5eddc7..4472ff280e9 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -2378,7 +2378,11 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BKE_pose_free(posen); @@ -2386,7 +2390,6 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; ob->ipoflag = ipoflago; } @@ -2457,7 +2460,11 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base * } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BLI_dlrbTree_free(&keys); BKE_pose_free(posen); @@ -2466,7 +2473,6 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base * CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; } @@ -2544,7 +2550,11 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base) } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); - + + /* before disposing of temp pose, use it to restore object to a sane state */ + BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL); + + /* clean up temporary pose */ ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */ BKE_pose_free(posen); @@ -2552,7 +2562,6 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base) CFRA = cfrao; ob->pose = poseo; arm->flag = flago; - BKE_pose_rebuild(ob, ob->data); ob->mode |= OB_MODE_POSE; } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 5069c4219c3..d2b3bcf6825 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -772,7 +772,8 @@ static int compareDrawOptionsEm(void *userData, int cur_index, int next_index) return 1; } -void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) +void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { Mesh *me = ob->data; @@ -871,7 +872,7 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs) if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) { /* get openl texture */ int mipmap = 1; - int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap) : 0; + int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, FALSE) : 0; float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; if (bindcode) { @@ -941,7 +942,8 @@ static int tex_mat_set_face_editmesh_cb(void *userData, int index) return !BM_elem_flag_test(efa, BM_ELEM_HIDDEN); } -void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, const int draw_flags) +void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { if ((!BKE_scene_use_new_shading_nodes(scene)) || (draw_flags & DRAW_MODIFIERS_PREVIEW)) { draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, draw_flags); @@ -1017,7 +1019,8 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o /* Vertex Paint and Weight Paint */ -void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags) +void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d, + Object *ob, DerivedMesh *dm, const int draw_flags) { DMSetDrawOptions facemask = NULL; Mesh *me = ob->data; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 8e9776e0e17..9ebd2351142 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -3164,7 +3164,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, { Mesh *me = ob->data; - BMFace *efa_act = BM_active_face_get(em->bm, FALSE); /* annoying but active faces is stored differently */ + BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); /* annoying but active faces is stored differently */ BMEdge *eed_act = NULL; BMVert *eve_act = NULL; @@ -3761,12 +3761,14 @@ static int drawDispListwire(ListBase *dlbase) } glEnd(); -/* (ton) this code crashes for me when resolv is 86 or higher... no clue */ -// glVertexPointer(3, GL_FLOAT, sizeof(float)*3*dl->nr, data + 3*nr); -// if (dl->flag & DL_CYCL_V) -// glDrawArrays(GL_LINE_LOOP, 0, dl->parts); -// else -// glDrawArrays(GL_LINE_STRIP, 0, dl->parts); +#if 0 + /* (ton) this code crashes for me when resolv is 86 or higher... no clue */ + glVertexPointer(3, GL_FLOAT, sizeof(float) * 3 * dl->nr, data + 3*nr); + if (dl->flag & DL_CYCL_V) + glDrawArrays(GL_LINE_LOOP, 0, dl->parts); + else + glDrawArrays(GL_LINE_STRIP, 0, dl->parts); +#endif } break; diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 10352033741..97130390c14 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -48,6 +48,7 @@ #include "BLI_math.h" #include "BLI_rand.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BKE_anim.h" #include "BKE_camera.h" @@ -1397,7 +1398,9 @@ unsigned int view3d_sample_backbuf(ViewContext *vc, int x, int y) glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); glReadBuffer(GL_BACK); - if (ENDIAN_ORDER == B_ENDIAN) SWITCH_INT(col); + if (ENDIAN_ORDER == B_ENDIAN) { + BLI_endian_switch_uint32(&col); + } return WM_framebuffer_to_index(col); } diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 71e87e73747..5bfabf4fc4a 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -175,7 +175,7 @@ void VIEW3D_OT_game_start(struct wmOperatorType *ot); int ED_view3d_boundbox_clip(RegionView3D * rv3d, float obmat[][4], struct BoundBox *bb); void view3d_smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *, - float *ofs, float *quat, float *dist, float *lens); + float *ofs, float *quat, float *dist, float *lens); void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); /* rect: for picking */ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 6f3cc744537..d8e394ab68c 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -2268,6 +2268,7 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m /* bbsel= */ /* UNUSED */ EDBM_backbuf_circle_init(vc, mval[0], mval[1], (short)(rad + 1.0f)); edbm_backbuf_check_and_select_tfaces(me, select == LEFTMOUSE); EDBM_backbuf_free(); + paintface_flush_flags(ob); } } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 8259ca64bad..fa7964b31ca 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -2431,8 +2431,9 @@ void initWarp(TransInfo *t) mul_m3_v3(t->data[i].mtx, center); mul_m4_v3(t->viewmat, center); sub_v3_v3(center, t->viewmat[3]); - if (i) + if (i) { minmax_v3v3_v3(min, max, center); + } else { copy_v3_v3(max, center); copy_v3_v3(min, center); @@ -2739,12 +2740,14 @@ static void headerResize(TransInfo *t, float vec[3], char *str) } } else { - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { spos += sprintf(spos, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], t->con.text, t->proptext); - else + } + else { spos += sprintf(spos, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + } } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { @@ -3647,9 +3650,10 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) { int i, do_split = t->scene->unit.flag & USER_UNIT_OPT_SPLIT ? 1 : 0; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { bUnit_AsString(&tvec[i * NUM_STR_REP_LEN], NUM_STR_REP_LEN, dvec[i] * t->scene->unit.scale_length, 4, t->scene->unit.system, B_UNIT_LENGTH, do_split, 1); + } } else { sprintf(&tvec[0], "%.4f", dvec[0]); @@ -3691,12 +3695,14 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) } } else { - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { spos += sprintf(spos, "Dx: %s Dy: %s (%s)%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], distvec, t->con.text, t->proptext); - else + } + else { spos += sprintf(spos, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, t->proptext, &autoik[0]); + } } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { @@ -4753,7 +4759,7 @@ static int createSlideVerts(TransInfo *t) BMEditMesh *em = me->edit_btmesh; BMesh *bm = em->bm; BMIter iter, iter2; - BMEdge *e, *e1 /*, *ee, *le */ /* UNUSED */; + BMEdge *e, *e1; BMVert *v, *v2, *first; BMLoop *l, *l1, *l2; TransDataSlideVert *sv_array; @@ -4765,9 +4771,10 @@ static int createSlideVerts(TransInfo *t) ARegion *ar = t->ar; float projectMat[4][4]; float mval[2] = {(float)t->mval[0], (float)t->mval[1]}; - float start[3] = {0.0f, 0.0f, 0.0f}, dir[3], end[3] = {0.0f, 0.0f, 0.0f}; + float start[3] = {0.0f, 0.0f, 0.0f}, end[3] = {0.0f, 0.0f, 0.0f}; float vec[3], vec2[3] /*, lastvec[3], size, dis=0.0, z */ /* UNUSED */; - int numsel, i, j; + float dir[3], maxdist, (*loop_dir)[3], *loop_maxdist; + int numsel, i, j, loop_nr, l_nr; if (t->spacetype == SPACE_VIEW3D) { /* background mode support */ @@ -4842,6 +4849,7 @@ static int createSlideVerts(TransInfo *t) } sv_array = MEM_callocN(sizeof(TransDataSlideVert) * j, "sv_array"); + loop_nr = 0; j = 0; while (1) { @@ -4904,6 +4912,8 @@ static int createSlideVerts(TransInfo *t) sv->v = v; sv->origvert = *v; + sv->loop_nr = loop_nr; + copy_v3_v3(sv->upvec, vec); if (l2) copy_v3_v3(sv->downvec, vec2); @@ -4926,6 +4936,7 @@ static int createSlideVerts(TransInfo *t) sv = sv_array + j + 1; sv->v = v; sv->origvert = *v; + sv->loop_nr = loop_nr; l = BM_face_other_edge_loop(l1->f, l1->e, v); sv->up = BM_edge_other_vert(l->e, v); @@ -4952,6 +4963,8 @@ static int createSlideVerts(TransInfo *t) BM_elem_flag_disable(v, BM_ELEM_TAG); BM_elem_flag_disable(v2, BM_ELEM_TAG); } while (e != first->e && l1); + + loop_nr++; } /* EDBM_flag_disable_all(em, BM_ELEM_SELECT); */ @@ -4959,21 +4972,24 @@ static int createSlideVerts(TransInfo *t) sld->sv = sv_array; sld->totsv = j; - /*find mouse vector*/ - /* dis = z = -1.0f; */ /* UNUSED */ - /* size = 50.0; */ /* UNUSED */ - /* zero_v3(lastvec); */ /* UNUSED */ + /* find mouse vectors, the global one, and one per loop in case we have + * multiple loops selected, in case they are oriented different */ zero_v3(dir); - /* ee = le = NULL; */ /* UNUSED */ + maxdist = -1.0f; + + loop_dir = MEM_callocN(sizeof(float) * 3 * loop_nr, "sv loop_dir"); + loop_maxdist = MEM_callocN(sizeof(float) * loop_nr, "sv loop_maxdist"); + for (j = 0; j < loop_nr; j++) + loop_maxdist[j] = -1.0f; + BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { BMIter iter2; BMEdge *e2; - float vec1[3], dis2, mval[2] = {t->mval[0], t->mval[1]}, d; + float vec1[3], mval[2] = {t->mval[0], t->mval[1]}, d; /* search cross edges for visible edge to the mouse cursor, * then use the shared vertex to calculate screen vector*/ - dis2 = -1.0f; for (i = 0; i < 2; i++) { v = i ? e->v1 : e->v2; BM_ITER_ELEM (e2, &iter2, v, BM_EDGES_OF_VERT) { @@ -5001,17 +5017,23 @@ static int createSlideVerts(TransInfo *t) ED_view3d_project_float_v3(ar, sv_array[j].up->co, vec2, projectMat); } else { - add_v3_v3v3(vec1, v->co, sv_array[j].upvec); + add_v3_v3v3(vec2, v->co, sv_array[j].upvec); ED_view3d_project_float_v3(ar, vec2, vec2, projectMat); } - + + /* global direction */ d = dist_to_line_segment_v2(mval, vec1, vec2); - if (dis2 == -1.0f || d < dis2) { - dis2 = d; - /* ee = e2; */ /* UNUSED */ - /* size = len_v3v3(vec1, vec2); */ /* UNUSED */ + if (maxdist == -1.0f || d < maxdist) { + maxdist = d; sub_v3_v3v3(dir, vec1, vec2); } + + /* per loop direction */ + l_nr = sv_array[j].loop_nr; + if (loop_maxdist[l_nr] == -1.0f || d < loop_maxdist[l_nr]) { + loop_maxdist[l_nr] = d; + sub_v3_v3v3(loop_dir[l_nr], vec1, vec2); + } } } } @@ -5045,6 +5067,14 @@ static int createSlideVerts(TransInfo *t) } BLI_smallhash_insert(&sld->vhash, (uintptr_t)sv_array->v, sv_array); + + /* switch up/down if loop direction is different from global direction */ + l_nr = sv_array->loop_nr; + if (dot_v3v3(loop_dir[l_nr], dir) < 0.0f) { + swap_v3_v3(sv_array->upvec, sv_array->downvec); + SWAP(BMVert, sv_array->vup, sv_array->vdown); + SWAP(BMVert*, sv_array->up, sv_array->down); + } } if (rv3d) @@ -5055,7 +5085,7 @@ static int createSlideVerts(TransInfo *t) /*zero out start*/ zero_v3(start); - + /*dir holds a vector along edge loop*/ copy_v3_v3(end, dir); mul_v3_fl(end, 0.5f); @@ -5072,6 +5102,8 @@ static int createSlideVerts(TransInfo *t) BLI_smallhash_release(&table); BMBVH_FreeBVH(btree); + MEM_freeN(loop_dir); + MEM_freeN(loop_maxdist); return 1; } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 8a7148aad95..e645cb2fed6 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -198,6 +198,8 @@ typedef struct TransDataSlideVert { float edge_len; float upvec[3], downvec[3]; + + int loop_nr; } TransDataSlideVert; typedef struct SlideData { diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 7f77341447d..e635c4b3fb8 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -4990,7 +4990,7 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o static void special_aftertrans_update__mask(bContext *C, TransInfo *t) { - Mask *mask; + Mask *mask = NULL; if (t->spacetype == SPACE_CLIP) { SpaceClip *sc = t->sa->spacedata.first; diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 89cb83e3661..b88ae68e00b 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -410,9 +410,8 @@ static void initSnappingMode(TransInfo *t) } else { /* force project off when not supported */ - if (ts->snap_mode != SCE_SNAP_MODE_FACE) { + if (t->spacetype == SPACE_IMAGE || ts->snap_mode != SCE_SNAP_MODE_FACE) t->tsnap.project = 0; - } t->tsnap.mode = ts->snap_mode; } diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 6d9f2732d8a..b0a2a24f25b 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -45,10 +45,10 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_packedFile.h" #include "ED_armature.h" +#include "ED_image.h" #include "ED_mesh.h" #include "ED_object.h" #include "ED_sculpt.h" @@ -67,6 +67,7 @@ void ED_editors_init(bContext *C) { + wmWindowManager *wm = CTX_wm_manager(C); Main *bmain = CTX_data_main(C); Scene *sce = CTX_data_scene(C); Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL; @@ -86,6 +87,9 @@ void ED_editors_init(bContext *C) ED_object_toggle_modes(C, mode); } } + + /* image editor paint mode */ + ED_space_image_paint_update(wm, sce->toolsettings); } /* frees all editmode stuff */ diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 1f78bc6bddf..d6794912043 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -415,7 +415,7 @@ static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob) glColor3ub(112, 112, 112); - if (me->mtface) { + if (me->mtpoly) { MPoly *mpoly = me->mpoly; MTexPoly *tface = me->mtpoly; MLoopUV *mloopuv; @@ -455,8 +455,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) StitchPreviewer *stitch_preview = uv_get_stitch_previewer(); - activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE); /* will be set to NULL if hidden */ - activef = BM_active_face_get(bm, FALSE); + activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE, FALSE); /* will be set to NULL if hidden */ + activef = BM_active_face_get(bm, FALSE, FALSE); ts = scene->toolsettings; drawfaces = draw_uvs_face_check(scene); diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 6f3e6bee850..5008c35e46a 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -174,6 +174,8 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im BMIter iter; MTexPoly *tf; int update = 0; + int sloppy = TRUE; + int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* skip assigning these procedural images... */ if (ima && (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)) @@ -190,8 +192,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im if (BKE_scene_use_new_shading_nodes(scene)) { /* new shading system, assign image in material */ - int sloppy = 1; - BMFace *efa = BM_active_face_get(em->bm, sloppy); + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) ED_object_assign_active_image(bmain, obedit, efa->mat_nr + 1, ima); @@ -2056,7 +2057,7 @@ static void UV_OT_select(wmOperatorType *ot) ot->name = "Select"; ot->description = "Select UV vertices"; ot->idname = "UV_OT_select"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->exec = select_exec; @@ -2101,7 +2102,7 @@ static void UV_OT_select_loop(wmOperatorType *ot) ot->name = "Loop Select"; ot->description = "Select a loop of connected UV vertices"; ot->idname = "UV_OT_select_loop"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->exec = select_loop_exec; @@ -2203,7 +2204,7 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot) ot->name = "Select Linked Pick"; ot->description = "Select all UV vertices linked under the mouse"; ot->idname = "UV_OT_select_linked_pick"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; /* api callbacks */ ot->invoke = select_linked_pick_invoke; diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index b4903390408..c1fb3ee3807 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -192,7 +192,10 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, handle = param_construct_begin(); if (correct_aspect) { - efa = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + + efa = BM_active_face_get(em->bm, sloppy, selected); if (efa) { float aspx, aspy; @@ -380,7 +383,10 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e handle = param_construct_begin(); if (correct_aspect) { - editFace = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + + editFace = BM_active_face_get(em->bm, sloppy, selected); if (editFace) { MTexPoly *tf; @@ -1003,7 +1009,9 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) static void correct_uv_aspect(BMEditMesh *em) { - BMFace *efa = BM_active_face_get(em->bm, TRUE); + int sloppy = TRUE; + int selected = FALSE; + BMFace *efa = BM_active_face_get(em->bm, sloppy, selected); BMLoop *l; BMIter iter, liter; MLoopUV *luv; diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 629283ce50d..1729ac06f5a 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -159,18 +159,18 @@ int GPU_buffer_legacy(struct DerivedMesh *dm ); typedef struct GPU_Buffers GPU_Buffers; GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4], - struct MFace *mface, struct MVert *mvert, - int *face_indices, int totface); + struct MFace *mface, struct MVert *mvert, + int *face_indices, int totface); void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert, - int *vert_indices, int totvert, const float *vmask); + int *vert_indices, int totvert, const float *vmask); GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid, - unsigned int **grid_hidden, int gridsize); + unsigned int **grid_hidden, int gridsize); void GPU_update_grid_buffers(GPU_Buffers *buffers, struct CCGElem **grids, - const struct DMFlagMat *grid_flag_mats, - int *grid_indices, int totgrid, const struct CCGKey *key); + const struct DMFlagMat *grid_flag_mats, + int *grid_indices, int totgrid, const struct CCGKey *key); void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial); diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 7a71f33d3d0..467adbe10b8 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -122,7 +122,7 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap); void GPU_paint_update_image(struct Image *ima, int x, int y, int w, int h, int mipmap); void GPU_update_images_framechange(void); int GPU_update_image_time(struct Image *ima, double time); -int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap); +int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap, int ncd); void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float *frect, int rectw, int recth, int mipmap, int use_hight_bit_depth, struct Image *ima); void GPU_create_gl_tex_compressed(unsigned int *bind, unsigned int *pix, int x, int y, int mipmap, struct Image *ima, struct ImBuf *ibuf); int GPU_upload_dxt_texture(struct ImBuf *ibuf); diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index b04da04258e..198d002ff0d 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -111,7 +111,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels); GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]); GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]); GPUTexture *GPU_texture_from_blender(struct Image *ima, - struct ImageUser *iuser, double time, int mipmap); + struct ImageUser *iuser, int ncd, double time, int mipmap); void GPU_texture_free(GPUTexture *tex); void GPU_texture_ref(GPUTexture *tex); diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index a725ff4385d..856b1f83001 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -107,7 +107,7 @@ typedef struct GPUNodeStack { GPUNodeLink *GPU_attribute(int type, const char *name); GPUNodeLink *GPU_uniform(float *num); GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data); -GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser); +GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, int ncd); GPUNodeLink *GPU_texture(int size, float *pixels); GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data); GPUNodeLink *GPU_socket(GPUNodeStack *sock); diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index a88a075383d..25990e8fc6e 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -761,7 +761,7 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap) /* now bind the textures */ for (input=inputs->first; input; input=input->next) { if (input->ima) - input->tex = GPU_texture_from_blender(input->ima, input->iuser, time, mipmap); + input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->imagencd, time, mipmap); if (input->tex && input->bindtex) { GPU_texture_bind(input->tex, input->texid); @@ -917,6 +917,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type) input->ima = link->ptr1; input->iuser = link->ptr2; + input->imagencd = link->imagencd; input->textarget = GL_TEXTURE_2D; input->textype = GPU_TEX2D; MEM_freeN(link); @@ -1109,13 +1110,14 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data) return link; } -GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser) +GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, int ncd) { GPUNodeLink *link = GPU_node_link_create(0); link->image= 1; link->ptr1= ima; link->ptr2= iuser; + link->imagencd= ncd; return link; } diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h index db334b8bf19..3010937a2f3 100644 --- a/source/blender/gpu/intern/gpu_codegen.h +++ b/source/blender/gpu/intern/gpu_codegen.h @@ -91,6 +91,7 @@ struct GPUNodeLink { const char *attribname; int image; + int imagencd; int texture; int texturesize; @@ -137,6 +138,7 @@ typedef struct GPUInput { struct Image *ima; /* image */ struct ImageUser *iuser;/* image user */ + int imagencd; /* image does not contain color data */ float *dynamicvec; /* vector data in case it is dynamic */ int dynamictype; /* origin of the dynamic uniform (GPUDynamicType) */ void *dynamicdata; /* data source of the dynamic uniform */ diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index d03913af417..4314a784511 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -422,7 +422,7 @@ static void gpu_verify_reflection(Image *ima) } } -int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap) +int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap, int ncd) { ImBuf *ibuf = NULL; unsigned int *bind = NULL; @@ -492,7 +492,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int } /* TODO unneeded when float images are correctly treated as linear always */ - if (ibuf->profile == IB_PROFILE_LINEAR_RGB) + if (!ncd && ibuf->profile == IB_PROFILE_LINEAR_RGB) do_color_management = TRUE; if (ibuf->rect==NULL) @@ -807,7 +807,7 @@ int GPU_set_tpage(MTFace *tface, int mipmap, int alphablend) gpu_verify_alpha_blend(alphablend); gpu_verify_reflection(ima); - if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) { + if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap, FALSE)) { GTS.curtile= GTS.tile; GTS.curima= GTS.ima; GTS.curtilemode= GTS.tilemode; diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 4974d57d64c..c5f427fbcab 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -522,7 +522,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels) return tex; } -GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap) +GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int ncd, double time, int mipmap) { GPUTexture *tex; GLint w, h, border, lastbindcode, bindcode; @@ -530,7 +530,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode); GPU_update_image_time(ima, time); - bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap); + bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, ncd); if (ima->gputexture) { ima->gputexture->bindcode = bindcode; diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index efb24375729..c831b92936f 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -645,7 +645,7 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink ** GPU_link(mat, "shade_light_texture", GPU_builtin(GPU_VIEW_POSITION), - GPU_image(mtex->tex->ima, &mtex->tex->iuser), + GPU_image(mtex->tex->ima, &mtex->tex->iuser, FALSE), GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob), &tex_rgb); texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb); @@ -1028,7 +1028,7 @@ static void do_material_tex(GPUShadeInput *shi) talpha = 0; if (tex && tex->type == TEX_IMAGE && tex->ima) { - GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb); + GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, FALSE), &tin, &trgb); rgbnor= TEX_RGB; if (tex->imaflag & TEX_USEALPHA) @@ -1104,7 +1104,7 @@ static void do_material_tex(GPUShadeInput *shi) if (tex->imaflag & TEX_NORMALMAP) { /* normalmap image */ - GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor); + GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser, TRUE), &tnor); if (mtex->norfac < 0.0f) GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor); @@ -1234,26 +1234,26 @@ static void do_material_tex(GPUShadeInput *shi) if (found_deriv_map) { GPU_link(mat, "mtex_bump_deriv", - texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac, &dBs, &dBt ); } else if ( mtex->texflag & MTEX_3TAP_BUMP) GPU_link(mat, "mtex_bump_tap3", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt ); else if ( mtex->texflag & MTEX_5TAP_BUMP) GPU_link(mat, "mtex_bump_tap5", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt ); else if ( mtex->texflag & MTEX_BICUBIC_BUMP ) { if (GPU_bicubic_bump_support()) { GPU_link(mat, "mtex_bump_bicubic", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt); } else { GPU_link(mat, "mtex_bump_tap5", - texco, GPU_image(tex->ima, &tex->iuser), tnorfac, + texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac, &dBs, &dBt); } } @@ -1263,7 +1263,7 @@ static void do_material_tex(GPUShadeInput *shi) float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; GPU_link(mat, "mtex_bump_apply_texspace", fDet, dBs, dBt, vR1, vR2, - GPU_image(tex->ima, &tex->iuser), texco, + GPU_image(tex->ima, &tex->iuser, TRUE), texco, GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc, &vNacc, &shi->vn ); } @@ -1396,10 +1396,10 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) GPU_material_enable_alpha(mat); if ((mat->scene->gm.flag & GAME_GLSL_NO_LIGHTS) || (ma->mode & MA_SHLESS)) { - shr->combined = shi->rgb; - shr->alpha = shi->alpha; GPU_link(mat, "set_rgb", shi->rgb, &shr->diff); GPU_link(mat, "set_rgb_zero", &shr->spec); + GPU_link(mat, "set_value", shi->alpha, &shr->alpha); + shr->combined = shr->diff; } else { if (GPU_link_changed(shi->emit) || ma->emit != 0.0f) { @@ -1418,7 +1418,8 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) material_lights(shi, shr); shr->combined = shr->diff; - shr->alpha = shi->alpha; + + GPU_link(mat, "set_value", shi->alpha, &shr->alpha); if (world) { /* exposure correction */ diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index 7a53fe247fe..c5722995d32 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -57,7 +57,6 @@ extern "C" { #include "BKE_global.h" #include "BKE_armature.h" #include "BKE_action.h" -#include "BKE_utildefines.h" #include "BKE_constraint.h" #include "DNA_object_types.h" #include "DNA_action_types.h" diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 439f52ed323..54a6a7f597e 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -492,8 +492,8 @@ void IMB_rectfill_alpha(struct ImBuf *ibuf, const float value); /* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, - const float col[4], const int do_color_management, - int x1, int y1, int x2, int y2); + const float col[4], const int do_color_management, + int x1, int y1, int x2, int y2); /* defined in metadata.c */ int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field); diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h index 16d10a5c41c..18816924a9b 100644 --- a/source/blender/imbuf/intern/IMB_indexer.h +++ b/source/blender/imbuf/intern/IMB_indexer.h @@ -31,7 +31,6 @@ #include #include -#include "BKE_utildefines.h" #include "IMB_anim.h" /* * separate animation index files to solve the following problems: diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index 60dd4f65594..8fa468949e7 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -69,7 +69,7 @@ typedef struct BMPHEADER { static int checkbmp(unsigned char *mem) { -#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[0])) +#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[1])) int ret_val = 0; BMPINFOHEADER bmi; diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 4108f0d89d7..458f0198aed 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -24,18 +24,21 @@ #include -#include "IMB_indexer.h" -#include "IMB_anim.h" -#include "AVI_avi.h" -#include "imbuf.h" #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" +#include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_path_util.h" #include "BLI_fileops.h" #include "BLI_math_base.h" +#include "IMB_indexer.h" +#include "IMB_anim.h" +#include "AVI_avi.h" +#include "imbuf.h" + #include "MEM_guardedalloc.h" #include "DNA_userdef_types.h" #include "BKE_global.h" @@ -208,10 +211,10 @@ struct anim_index *IMB_indexer_open(const char *name) if (((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V'))) { for (i = 0; i < idx->num_entries; i++) { - SWITCH_INT(idx->entries[i].frameno); - SWITCH_INT64(idx->entries[i].seek_pos); - SWITCH_INT64(idx->entries[i].seek_pos_dts); - SWITCH_INT64(idx->entries[i].pts); + BLI_endian_switch_int32(&idx->entries[i].frameno); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos_dts); + BLI_endian_switch_int64((int64_t *)&idx->entries[i].pts); } } diff --git a/source/blender/imbuf/intern/indexer_dv.c b/source/blender/imbuf/intern/indexer_dv.c index 4c6b750aa41..6b960a18277 100644 --- a/source/blender/imbuf/intern/indexer_dv.c +++ b/source/blender/imbuf/intern/indexer_dv.c @@ -22,9 +22,12 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include "IMB_indexer.h" #include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_path_util.h" + +#include "IMB_indexer.h" #include typedef struct indexer_dv_bitstream { diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 6a234b8e29a..2a2aedb49ff 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -39,8 +39,6 @@ #include "BLI_fileops.h" #include "BLI_md5.h" -#include "BKE_utildefines.h" - #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index afef2365de4..cfc49d8cef5 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -29,18 +29,20 @@ #include "zlib.h" +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #include "BLI_fileops.h" -#include "BKE_utildefines.h" +#include "BLO_blend_defs.h" + #include "BKE_global.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" -#include "MEM_guardedalloc.h" - /* extracts the thumbnail from between the 'REND' and the 'GLOB' * chunks of the header, don't use typical blend loader because its too slow */ @@ -78,7 +80,7 @@ static ImBuf *loadblend_thumb(gzFile gzfile) while (gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) { if (endian_switch) - SWITCH_INT(bhead[1]); /* length */ + BLI_endian_switch_int32(&bhead[1]); /* length */ if (bhead[0] == REND) { gzseek(gzfile, bhead[1], SEEK_CUR); /* skip to the next */ @@ -97,8 +99,8 @@ static ImBuf *loadblend_thumb(gzFile gzfile) return NULL; if (endian_switch) { - SWITCH_INT(size[0]); - SWITCH_INT(size[1]); + BLI_endian_switch_int32(&size[0]); + BLI_endian_switch_int32(&size[1]); } /* length */ bhead[1] -= sizeof(int) * 2; diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index a765ac5c3b4..6d1e3c16631 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -225,16 +225,6 @@ static int isqtime(const char *name) static char ffmpeg_last_error[1024]; -void silence_log_ffmpeg(int quiet) -{ - if (quiet) { - av_log_set_level(AV_LOG_QUIET); - } - else { - av_log_set_level(AV_LOG_DEBUG); - } -} - void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg) { if (ELEM(level, AV_LOG_FATAL, AV_LOG_ERROR)) { @@ -244,8 +234,10 @@ void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg) ffmpeg_last_error[n - 1] = '\0'; } - /* call default logger to print all message to console */ - av_log_default_callback(ptr, level, format, arg); + if (G.debug & G_DEBUG_FFMPEG) { + /* call default logger to print all message to console */ + av_log_default_callback(ptr, level, format, arg); + } } void IMB_ffmpeg_init(void) @@ -253,13 +245,6 @@ void IMB_ffmpeg_init(void) av_register_all(); avdevice_register_all(); - if ((G.debug & G_DEBUG_FFMPEG) == 0) { - silence_log_ffmpeg(1); - } - else { - silence_log_ffmpeg(0); - } - ffmpeg_last_error[0] = '\0'; /* set own callback which could store last error to report to UI */ diff --git a/source/blender/makesdna/DNA_ipo_types.h b/source/blender/makesdna/DNA_ipo_types.h index e3ab6b4a7db..6bf8dbbe73a 100644 --- a/source/blender/makesdna/DNA_ipo_types.h +++ b/source/blender/makesdna/DNA_ipo_types.h @@ -65,8 +65,8 @@ typedef struct IpoDriver { typedef struct IpoCurve { struct IpoCurve *next, *prev; - struct BPoint *bp; /* array of BPoints (sizeof(BPoint)*totvert) - i.e. baked/imported data */ - struct BezTriple *bezt; /* array of BezTriples (sizeof(BezTriple)*totvert) - i.e. user-editable keyframes */ + struct BPoint *bp; /* array of BPoints (sizeof(BPoint) * totvert) - i.e. baked/imported data */ + struct BezTriple *bezt; /* array of BezTriples (sizeof(BezTriple) * totvert) - i.e. user-editable keyframes */ rctf maxrct, totrct; /* bounding boxes */ diff --git a/source/blender/makesdna/DNA_sdna_types.h b/source/blender/makesdna/DNA_sdna_types.h index ec02db192fd..8b2e7645823 100644 --- a/source/blender/makesdna/DNA_sdna_types.h +++ b/source/blender/makesdna/DNA_sdna_types.h @@ -81,12 +81,7 @@ typedef struct BHead4 { # typedef struct BHead8 { int code, len; -#if defined(WIN32) && !defined(FREE_WINDOWS) - /* This is a compiler type! */ - __int64 old; -#else - long long old; -#endif + int64_t old; int SDNAnr, nr; } BHead8; diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 62a09e65191..d2ff8d13124 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -51,7 +51,7 @@ # define __func__ __FUNCTION__ #endif -/* copied from BKE_utildefines.h ugh */ +/* copied from BLI_utildefines.h ugh */ #ifdef __GNUC__ # define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) #else @@ -2881,8 +2881,8 @@ static const char *cpp_classes = "" " T data[Tsize];\n" "\n" " Array() {}\n" -" Array(const Array& other) { memcpy(data, other.data, sizeof(T)*Tsize); }\n" -" const Array& operator=(const Array& other) { memcpy(data, other.data, sizeof(T)*Tsize); " +" Array(const Array& other) { memcpy(data, other.data, sizeof(T) * Tsize); }\n" +" const Array& operator=(const Array& other) { memcpy(data, other.data, sizeof(T) * Tsize); " "return *this; }\n" "\n" " operator T*() { return data; }\n" diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 738e7ad2219..be70405d165 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -146,6 +146,18 @@ static void rna_Armature_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene), WM_main_add_notifier(NC_GEOM | ND_DATA, id); } +/* called whenever a bone is renamed */ +static void rna_Bone_update_renamed(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +{ + ID *id = ptr->id.data; + + /* redraw view */ + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + /* update animation channels */ + WM_main_add_notifier(NC_ANIMATION | ND_ANIMCHAN, id); +} + static void rna_Bone_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { ID *id = ptr->id.data; @@ -470,7 +482,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone) RNA_def_struct_name_property(srna, prop); if (editbone) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_EditBone_name_set"); else RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Bone_name_set"); - RNA_def_property_update(prop, 0, "rna_Armature_redraw_data"); + RNA_def_property_update(prop, 0, "rna_Bone_update_renamed"); /* flags */ prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER_MEMBER); diff --git a/source/blender/makesrna/intern/rna_camera_api.c b/source/blender/makesrna/intern/rna_camera_api.c index 2d19047ef89..75941fa224f 100644 --- a/source/blender/makesrna/intern/rna_camera_api.c +++ b/source/blender/makesrna/intern/rna_camera_api.c @@ -29,9 +29,7 @@ #include #include - #include "RNA_define.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c index e84a290acb8..daa661175a1 100644 --- a/source/blender/makesrna/intern/rna_fluidsim.c +++ b/source/blender/makesrna/intern/rna_fluidsim.c @@ -24,15 +24,16 @@ * \ingroup RNA */ - #include +#include "DNA_object_fluidsim.h" + +#include "BLI_path_util.h" + #include "RNA_define.h" #include "rna_internal.h" -#include "DNA_object_fluidsim.h" - #include "WM_api.h" #include "WM_types.h" diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c index e246c6975b5..eb12a02aa99 100644 --- a/source/blender/makesrna/intern/rna_gpencil.c +++ b/source/blender/makesrna/intern/rna_gpencil.c @@ -203,7 +203,7 @@ static void rna_def_gpencil_layer(BlenderRNA *brna) RNA_def_property_editable_func(prop, "rna_GPencilLayer_active_frame_editable"); /* Drawing Color */ - prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); + prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_array(prop, 3); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Color", "Color for all strokes in this layer"); diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 96c5ff991f6..74b3c431183 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -24,16 +24,15 @@ * \ingroup RNA */ - #include #include +#include "BLI_path_util.h" + #include "RNA_define.h" #include "rna_internal.h" -#include "BKE_utildefines.h" - #ifdef RNA_RUNTIME #include "BKE_main.h" diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 59eae3259b4..8a2374060cf 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -35,12 +35,13 @@ #include "DNA_ID.h" +#include "BLI_path_util.h" + #include "RNA_define.h" #include "RNA_access.h" #include "RNA_enum_types.h" -#include "rna_internal.h" -#include "BKE_utildefines.h" +#include "rna_internal.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c index c21d029a6b7..a755e130bb7 100644 --- a/source/blender/makesrna/intern/rna_render.c +++ b/source/blender/makesrna/intern/rna_render.c @@ -24,11 +24,12 @@ * \ingroup RNA */ - #include #include "DNA_scene_types.h" +#include "BLI_path_util.h" + #include "RNA_define.h" #include "RNA_enum_types.h" @@ -37,7 +38,6 @@ #include "RE_engine.h" #include "RE_pipeline.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index 61be48f3f02..69b61b47d8a 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -32,13 +32,13 @@ #include #include +#include "BLI_path_util.h" + #include "RNA_define.h" #include "DNA_anim_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BKE_utildefines.h" - #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index ce5f39d0b42..385e82cab35 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -532,12 +532,7 @@ static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr) static void rna_SpaceImageEditor_mode_update(Main *bmain, Scene *scene, PointerRNA *ptr) { - SpaceImage *sima = (SpaceImage *)(ptr->data); - if (sima->mode == SI_MODE_PAINT) { - BKE_paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); - - ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); - } + ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); } static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_texture_api.c b/source/blender/makesrna/intern/rna_texture_api.c index ff8940129a1..e62b3ecd804 100644 --- a/source/blender/makesrna/intern/rna_texture_api.c +++ b/source/blender/makesrna/intern/rna_texture_api.c @@ -24,14 +24,13 @@ * \ingroup RNA */ - #include #include #include +#include "BLI_path_util.h" #include "RNA_define.h" -#include "BKE_utildefines.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index d910ed7900c..ae4d5dc493e 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -83,9 +83,10 @@ void rna_event_timer_remove(struct wmWindowManager *wm, wmTimer *timer) } static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, const char *idname, int type, int value, - int any, int shift, int ctrl, int alt, int oskey, int keymodifier) + int any, int shift, int ctrl, int alt, int oskey, int keymodifier, int head) { /* wmWindowManager *wm = CTX_wm_manager(C); */ + wmKeyMapItem *kmi = NULL; char idname_bl[OP_MAX_TYPENAME]; int modifier = 0; @@ -103,8 +104,19 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, cons if (oskey) modifier |= KM_OSKEY; if (any) modifier = KM_ANY; - - return WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); + + /* create keymap item */ + kmi = WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); + + /* [#32437] allow scripts to define hotkeys that get added to start of keymap + * so that they stand a chance against catch-all defines later on + */ + if (head) { + BLI_remlink(&km->items, kmi); + BLI_addhead(&km->items, kmi); + } + + return kmi; } static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km, ReportList *reports, const char *propvalue_str, @@ -425,6 +437,9 @@ void RNA_api_keymapitems(StructRNA *srna) RNA_def_boolean(func, "alt", 0, "Alt", ""); RNA_def_boolean(func, "oskey", 0, "OS Key", ""); RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", ""); + RNA_def_boolean(func, "head", 0, "At Head", + "Force item to be added at start (not end) of key map so that " + "it doesn't get blocked by an existing key map item"); parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item"); RNA_def_function_return(func, parm); diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 1c98880c3db..9acac6d00cd 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -51,7 +51,6 @@ #include "BKE_fluidsim.h" /* ensure definitions here match */ #include "BKE_cdderivedmesh.h" #include "BKE_mesh.h" -#include "BKE_utildefines.h" #include "BKE_global.h" /* G.main->name only */ #include "MOD_fluidsim_util.h" diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index 6f3d47b3426..febc4190fdf 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -43,7 +43,6 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_deform.h" -#include "BKE_utildefines.h" #include "BKE_tessmesh.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 21836453eed..3bf8b9ffacc 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -37,7 +37,6 @@ #include "BKE_global.h" #include "BKE_modifier.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" #include "BLI_blenlib.h" #include "BLI_math.h" diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 37444b6da92..55750ca1bab 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -48,7 +48,6 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_tracking.h" -#include "BKE_utildefines.h" #include "node_common.h" #include "node_exec.h" diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c index 399cb1d1557..2d9b9348668 100644 --- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c +++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c @@ -33,8 +33,6 @@ #include #include "BLI_path_util.h" -#include "BKE_utildefines.h" - #include "node_composite_util.h" #include "IMB_imbuf.h" diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index ffa636fa952..fdbe82efeda 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -45,7 +45,6 @@ #include "BKE_main.h" #include "BLI_math.h" #include "BKE_node.h" -#include "BKE_utildefines.h" #include "RNA_access.h" #include "RNA_types.h" diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index fa623eaad3d..ad907c317f8 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -49,7 +49,6 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_scene.h" -#include "BKE_utildefines.h" #include "GPU_material.h" @@ -66,15 +65,15 @@ static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func) Lamp *la; World *wo; - for (ma= main->mat.first; ma; ma= ma->id.next) + for (ma = main->mat.first; ma; ma = ma->id.next) if (ma->nodetree) func(calldata, &ma->id, ma->nodetree); - for (la= main->lamp.first; la; la= la->id.next) + for (la = main->lamp.first; la; la = la->id.next) if (la->nodetree) func(calldata, &la->id, la->nodetree); - for (wo= main->world.first; wo; wo= wo->id.next) + for (wo = main->world.first; wo; wo = wo->id.next) if (wo->nodetree) func(calldata, &wo->id, wo->nodetree); } @@ -101,7 +100,7 @@ static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) bNode *node, *node_next; /* replace muted nodes and reroute nodes by internal links */ - for (node= localtree->nodes.first; node; node= node_next) { + for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { @@ -116,15 +115,15 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) bNode *lnode; /* copy over contents of previews */ - for (lnode= localtree->nodes.first; lnode; lnode= lnode->next) { + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { - bNode *node= lnode->new_node; + bNode *node = lnode->new_node; if (node->preview && node->preview->rect) { if (lnode->preview && lnode->preview->rect) { - int xsize= node->preview->xsize; - int ysize= node->preview->ysize; - memcpy(node->preview->rect, lnode->preview->rect, 4*xsize + xsize*ysize*sizeof(char)*4); + int xsize = node->preview->xsize; + int ysize = node->preview->ysize; + memcpy(node->preview->rect, lnode->preview->rect, 4 * xsize + xsize * ysize * sizeof(char) * 4); } } } @@ -176,7 +175,7 @@ void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *); void set_node_shader_lamp_loop(void (*lamp_loop_func)(ShadeInput *, ShadeResult *)) { - node_shader_lamp_loop= lamp_loop_func; + node_shader_lamp_loop = lamp_loop_func; } @@ -203,10 +202,10 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree, int use_tree_data) exec = ntree_exec_begin(ntree); /* allocate the thread stack listbase array */ - exec->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array"); + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node= exec->nodetree->nodes.first; node; node= node->next) - node->need_exec= 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; if (use_tree_data) { /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, @@ -224,19 +223,19 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree, int use_tree_data) void ntreeShaderEndExecTree(bNodeTreeExec *exec, int use_tree_data) { if (exec) { - bNodeTree *ntree= exec->nodetree; + bNodeTree *ntree = exec->nodetree; bNodeThreadStack *nts; int a; if (exec->threadstack) { - for (a=0; athreadstack[a].first; nts; nts=nts->next) + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } MEM_freeN(exec->threadstack); - exec->threadstack= NULL; + exec->threadstack = NULL; } ntree_exec_end(exec); @@ -260,8 +259,8 @@ void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) bNodeTreeExec *exec = ntree->execdata; /* convert caller data to struct */ - scd.shi= shi; - scd.shr= shr; + scd.shi = shi; + scd.shr = shr; /* each material node has own local shaderesult, with optional copying */ memset(shr, 0, sizeof(ShadeResult)); @@ -276,14 +275,14 @@ void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) exec = ntree->execdata; } - nts= ntreeGetThreadStack(exec, shi->thread); + nts = ntreeGetThreadStack(exec, shi->thread); ntreeExecThreadNodes(exec, nts, &scd, shi->thread); ntreeReleaseThreadStack(nts); // \note: set material back to preserved material shi->mat = mat; /* better not allow negative for now */ - if (shr->combined[0]<0.0f) shr->combined[0]= 0.0f; - if (shr->combined[1]<0.0f) shr->combined[1]= 0.0f; - if (shr->combined[2]<0.0f) shr->combined[2]= 0.0f; + if (shr->combined[0] < 0.0f) shr->combined[0] = 0.0f; + if (shr->combined[1] < 0.0f) shr->combined[1] = 0.0f; + if (shr->combined[2] < 0.0f) shr->combined[2] = 0.0f; } diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c index 5be8925b556..ddfcb9476f4 100644 --- a/source/blender/nodes/shader/nodes/node_shader_particle_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c @@ -31,6 +31,13 @@ static bNodeSocketTemplate outputs[] = { { SOCK_FLOAT, 0, "Index" }, { SOCK_FLOAT, 0, "Age" }, { SOCK_FLOAT, 0, "Lifetime" }, + { SOCK_VECTOR, 0, "Location" }, + #if 0 /* quaternion sockets not yet supported */ + { SOCK_QUATERNION, 0, "Rotation" }, + #endif + { SOCK_FLOAT, 0, "Size" }, + { SOCK_VECTOR, 0, "Velocity" }, + { SOCK_VECTOR, 0, "Angular Velocity" }, { -1, 0, "" } }; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c index 572f06e007b..e857d0571cd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -58,6 +58,8 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; + NodeTexImage *tex = node->storage; + int ncd = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) return GPU_stack_link(mat, "node_tex_environment_empty", in, out); @@ -67,7 +69,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser)); + return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, ncd)); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index 176c50bcabb..c492fe9efc7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -58,6 +58,8 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; + NodeTexImage *tex = node->storage; + int ncd = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) return GPU_stack_link(mat, "node_tex_image_empty", in, out); @@ -67,7 +69,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser)); + return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, ncd)); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c index 3f90d4fbcd5..73c3b846fe3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_texture.c +++ b/source/blender/nodes/shader/nodes/node_shader_texture.c @@ -122,7 +122,7 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, GPUNodeStack *in, G Tex *tex = (Tex*)node->id; if (tex && tex->type == TEX_IMAGE && tex->ima) { - GPUNodeLink *texlink = GPU_image(tex->ima, NULL); + GPUNodeLink *texlink = GPU_image(tex->ima, NULL, FALSE); return GPU_stack_link(mat, "texture_image", in, out, texlink); } else diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index 063cc31e6f6..9656d93f1b0 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -58,7 +58,7 @@ static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func) { Tex *tx; - for (tx= main->tex.first; tx; tx= tx->id.next) { + for (tx = main->tex.first; tx; tx = tx->id.next) { if (tx->nodetree) { func(calldata, &tx->id, tx->nodetree); } @@ -83,7 +83,7 @@ static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) bNode *node, *node_next; /* replace muted nodes and reroute nodes by internal links */ - for (node= localtree->nodes.first; node; node= node_next) { + for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { @@ -98,15 +98,15 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) bNode *lnode; /* copy over contents of previews */ - for (lnode= localtree->nodes.first; lnode; lnode= lnode->next) { + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { - bNode *node= lnode->new_node; + bNode *node = lnode->new_node; if (node->preview && node->preview->rect) { if (lnode->preview && lnode->preview->rect) { - int xsize= node->preview->xsize; - int ysize= node->preview->ysize; - memcpy(node->preview->rect, lnode->preview->rect, 4*xsize + xsize*ysize*sizeof(char)*4); + int xsize = node->preview->xsize; + int ysize = node->preview->ysize; + memcpy(node->preview->rect, lnode->preview->rect, 4 * xsize + xsize * ysize * sizeof(char) * 4); } } } @@ -141,15 +141,15 @@ int ntreeTexTagAnimated(bNodeTree *ntree) { bNode *node; - if (ntree==NULL) return 0; + if (ntree == NULL) return 0; - for (node= ntree->nodes.first; node; node= node->next) { - if (node->type==TEX_NODE_CURVE_TIME) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == TEX_NODE_CURVE_TIME) { nodeUpdate(ntree, node); return 1; } - else if (node->type==NODE_GROUP) { - if ( ntreeTexTagAnimated((bNodeTree *)node->id) ) { + else if (node->type == NODE_GROUP) { + if (ntreeTexTagAnimated((bNodeTree *)node->id) ) { return 1; } } @@ -178,10 +178,10 @@ bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree, int use_tree_data) exec = ntree_exec_begin(ntree); /* allocate the thread stack listbase array */ - exec->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array"); + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node= exec->nodetree->nodes.first; node; node= node->next) - node->need_exec= 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; if (use_tree_data) { /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, @@ -200,9 +200,9 @@ static void tex_free_delegates(bNodeTreeExec *exec) bNodeStack *ns; int th, a; - for (th=0; ththreadstack[th].first; nts; nts=nts->next) - for (ns= nts->stack, a=0; astacksize; a++, ns++) + for (th = 0; th < BLENDER_MAX_THREADS; th++) + for (nts = exec->threadstack[th].first; nts; nts = nts->next) + for (ns = nts->stack, a = 0; a < exec->stacksize; a++, ns++) if (ns->data && !ns->is_copy) MEM_freeN(ns->data); } @@ -213,21 +213,21 @@ static void tex_free_delegates(bNodeTreeExec *exec) void ntreeTexEndExecTree(bNodeTreeExec *exec, int use_tree_data) { if (exec) { - bNodeTree *ntree= exec->nodetree; + bNodeTree *ntree = exec->nodetree; bNodeThreadStack *nts; int a; if (exec->threadstack) { tex_free_delegates(exec); - for (a=0; athreadstack[a].first; nts; nts=nts->next) + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } MEM_freeN(exec->threadstack); - exec->threadstack= NULL; + exec->threadstack = NULL; } ntree_exec_end(exec); @@ -254,10 +254,10 @@ int ntreeTexExecTree( MTex *mtex ) { TexCallData data; - float *nor= texres->nor; + float *nor = texres->nor; int retval = TEX_INT; bNodeThreadStack *nts = NULL; - bNodeTreeExec *exec= nodes->execdata; + bNodeTreeExec *exec = nodes->execdata; data.co = co; data.dxt = dxt; @@ -267,9 +267,9 @@ int ntreeTexExecTree( data.do_preview = preview; data.thread = thread; data.which_output = which_output; - data.cfra= cfra; - data.mtex= mtex; - data.shi= shi; + data.cfra = cfra; + data.mtex = mtex; + data.shi = shi; /* ensure execdata is only initialized once */ if (!exec) { @@ -278,10 +278,10 @@ int ntreeTexExecTree( ntreeTexBeginExecTree(nodes, 1); BLI_unlock_thread(LOCK_NODES); - exec= nodes->execdata; + exec = nodes->execdata; } - nts= ntreeGetThreadStack(exec, thread); + nts = ntreeGetThreadStack(exec, thread); ntreeExecThreadNodes(exec, nts, &data, thread); ntreeReleaseThreadStack(nts); @@ -289,7 +289,7 @@ int ntreeTexExecTree( retval |= TEX_RGB; /* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was set * however, the texture code checks this for other reasons (namely, a normal is required for material) */ - texres->nor= nor; + texres->nor = nor; return retval; } diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 520773c1ddf..2e4d4e870b8 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -402,6 +402,15 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) if (PyBytes_Check(py_str)) { return PyBytes_AS_STRING(py_str); } +#ifdef WIN32 + /* bug [#31856] oddly enough, Python3.2 --> 3.3 on Windows will throw an + * exception here this needs to be fixed in python: + * see: bugs.python.org/issue15859 */ + else if (!PyUnicode_Check(py_str)) { + PyErr_BadArgument(); + return NULL; + } +#endif else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { return PyBytes_AS_STRING(*coerce); } diff --git a/source/blender/quicktime/apple/qtkit_export.m b/source/blender/quicktime/apple/qtkit_export.m index 47df4c7363f..bb87fe21c49 100644 --- a/source/blender/quicktime/apple/qtkit_export.m +++ b/source/blender/quicktime/apple/qtkit_export.m @@ -318,7 +318,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R if(qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport"); - [QTMovie enterQTKitOnThread]; + [QTMovie enterQTKitOnThread]; /* Check first if the QuickTime 7.2.1 initToWritableFile: method is available */ if ([[[[QTMovie alloc] init] autorelease] respondsToSelector:@selector(initToWritableFile:error:)] != YES) { @@ -328,7 +328,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R else { makeqtstring(rd, name); qtexport->filename = [[NSString alloc] initWithCString:name - encoding:[NSString defaultCStringEncoding]]; + encoding:[NSString defaultCStringEncoding]]; qtexport->movie = nil; qtexport->audioFile = NULL; @@ -354,7 +354,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R strcpy(extension,".aiff"); break; } - + tmpnam(name); strcat(name, extension); outputFileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,(UInt8*) name, strlen(name), false); @@ -362,7 +362,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R if (outputFileURL) { qtexport->audioFileName = [[NSString alloc] initWithCString:name - encoding:[NSString defaultCStringEncoding]]; + encoding:[NSString defaultCStringEncoding]]; qtexport->audioInputFormat.mSampleRate = U.audiorate; qtexport->audioInputFormat.mFormatID = kAudioFormatLinearPCM; @@ -471,7 +471,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R qtexport->audioOutputFormat.mBytesPerFrame = qtexport->audioOutputFormat.mBytesPerPacket; break; } - + err = AudioFileCreateWithURL(outputFileURL, audioFileType, &qtexport->audioOutputFormat, kAudioFileFlags_EraseFile, &qtexport->audioFile); CFRelease(outputFileURL); @@ -489,27 +489,27 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R else { UInt32 prop,propSize; /* Set up codec properties */ - if (rd->qtcodecsettings.audiocodecType == kAudioFormatMPEG4AAC) { /*Lossy compressed format*/ + if (rd->qtcodecsettings.audiocodecType == kAudioFormatMPEG4AAC) { /* Lossy compressed format */ prop = rd->qtcodecsettings.audioBitRate; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterEncodeBitRate, - sizeof(prop), &prop); + sizeof(prop), &prop); if (rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_CODEC_ISCBR) prop = kAudioCodecBitRateControlMode_Constant; else prop = kAudioCodecBitRateControlMode_LongTermAverage; AudioConverterSetProperty(qtexport->audioConverter, kAudioCodecPropertyBitRateControlMode, - sizeof(prop), &prop); + sizeof(prop), &prop); } /* Conversion quality : if performance impact then offer degraded option */ - if ((rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_RESAMPLE_NOHQ) == 0) { + if ((rd->qtcodecsettings.audioCodecFlags & QTAUDIO_FLAG_RESAMPLE_NOHQ) == 0) { prop = kAudioConverterSampleRateConverterComplexity_Mastering; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterSampleRateConverterComplexity, - sizeof(prop), &prop); + sizeof(prop), &prop); prop = kAudioConverterQuality_Max; AudioConverterSetProperty(qtexport->audioConverter, kAudioConverterSampleRateConverterQuality, - sizeof(prop), &prop); + sizeof(prop), &prop); } write_cookie(qtexport->audioConverter, qtexport->audioFile); @@ -517,29 +517,30 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R /* Allocate output buffer */ if (qtexport->audioOutputFormat.mBytesPerPacket ==0) /* VBR */ AudioConverterGetProperty(qtexport->audioConverter, kAudioConverterPropertyMaximumOutputPacketSize, - &propSize, &qtexport->audioCodecMaxOutputPacketSize); + &propSize, &qtexport->audioCodecMaxOutputPacketSize); else qtexport->audioCodecMaxOutputPacketSize = qtexport->audioOutputFormat.mBytesPerPacket; qtexport->audioInputBuffer = MEM_mallocN(AUDIOOUTPUTBUFFERSIZE, "qt_audio_inputPacket"); qtexport->audioOutputBuffer = MEM_mallocN(AUDIOOUTPUTBUFFERSIZE, "qt_audio_outputPacket"); - qtexport->audioOutputPktDesc = MEM_mallocN(sizeof(AudioStreamPacketDescription)*AUDIOOUTPUTBUFFERSIZE/qtexport->audioCodecMaxOutputPacketSize, - "qt_audio_pktdesc"); + qtexport->audioOutputPktDesc = MEM_mallocN(sizeof(AudioStreamPacketDescription) * AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize, + "qt_audio_pktdesc"); } } } - + if (err == noErr) { - qtexport->videoTempFileName = [[NSString alloc] initWithCString:tmpnam(nil) - encoding:[NSString defaultCStringEncoding]]; - if (qtexport->videoTempFileName) + qtexport->videoTempFileName = [[NSString alloc] initWithCString:tmpnam(nil) + encoding:[NSString defaultCStringEncoding]]; + if (qtexport->videoTempFileName) { qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->videoTempFileName error:&error]; + } } } else qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->filename error:&error]; - + if(qtexport->movie == nil) { BKE_report(reports, RPT_ERROR, "Unable to create quicktime movie."); success= 0; @@ -585,7 +586,7 @@ int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, R specs.rate = U.audiorate; qtexport->audioInputDevice = AUD_openReadDevice(specs); AUD_playDevice(qtexport->audioInputDevice, scene->sound_scene, rd->sfra * rd->frs_sec_base / rd->frs_sec); - + qtexport->audioOutputPktPos = 0; qtexport->audioTotalExportedFrames = 0; qtexport->audioTotalSavedFrames = 0; @@ -655,13 +656,13 @@ int append_qt(struct RenderData *rd, int start_frame, int frame, int *pixels, in audioPacketsConverted = AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize; err = AudioConverterFillComplexBuffer(qtexport->audioConverter, AudioConverterInputCallback, - NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc); + NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc); if (audioPacketsConverted) { AudioFileWritePackets(qtexport->audioFile, false, qtexport->audioBufferList.mBuffers[0].mDataByteSize, - qtexport->audioOutputPktDesc, qtexport->audioOutputPktPos, &audioPacketsConverted, qtexport->audioOutputBuffer); + qtexport->audioOutputPktDesc, qtexport->audioOutputPktPos, &audioPacketsConverted, qtexport->audioOutputBuffer); qtexport->audioOutputPktPos += audioPacketsConverted; - if (qtexport->audioOutputFormat.mFramesPerPacket) { + if (qtexport->audioOutputFormat.mFramesPerPacket) { // this is the common case: format has constant frames per packet qtexport->audioTotalSavedFrames += (audioPacketsConverted * qtexport->audioOutputFormat.mFramesPerPacket); } @@ -751,8 +752,8 @@ void end_qt(void) } /* Save file */ - dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] - forKey:QTMovieFlatten]; + dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] + forKey:QTMovieFlatten]; if (dict) { [qtexport->movie writeToFile:qtexport->filename withAttributes:dict]; diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index 604cd940fab..c07ed42332f 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -65,7 +65,7 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove); struct Material *RE_init_sample_material(struct Material *orig_mat, struct Scene *scene); void RE_free_sample_material(struct Material *mat); void RE_sample_material_color(struct Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3], - int face_index, short hit_quad, struct DerivedMesh *orcoDm, struct Object *ob); + int face_index, short hit_quad, struct DerivedMesh *orcoDm, struct Object *ob); #endif /* __RE_RENDER_EXT_H__ */ diff --git a/source/blender/render/intern/include/pixelshading.h b/source/blender/render/intern/include/pixelshading.h index 00d731912b6..30d574694b2 100644 --- a/source/blender/render/intern/include/pixelshading.h +++ b/source/blender/render/intern/include/pixelshading.h @@ -44,9 +44,9 @@ * \return pointer to the object */ int shadeHaloFloat(HaloRen *har, - float *col, int zz, - float dist, float xn, - float yn, short flarec); + float *col, int zz, + float dist, float xn, + float yn, short flarec); /** * Render the sky at pixel (x, y). diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 667429ca106..984efdbb563 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -55,7 +55,6 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_sequencer.h" -#include "BKE_utildefines.h" #include "BKE_writeavi.h" /* <------ should be replaced once with generic movie module */ #include "BLI_math.h" diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index a2b0cd09932..603e49766b1 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -38,7 +38,6 @@ #include "BKE_global.h" #include "BKE_main.h" #include "BKE_report.h" -#include "BKE_utildefines.h" #include "BLI_fileops.h" #include "BLI_listbase.h" diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c index b842cab1d29..8c9df496dd6 100644 --- a/source/blender/render/intern/source/texture_ocean.c +++ b/source/blender/render/intern/source/texture_ocean.c @@ -36,7 +36,6 @@ #include "BKE_modifier.h" #include "BKE_ocean.h" -#include "BKE_utildefines.h" #include "render_types.h" #include "RE_shader_ext.h" diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index 78dbd253cd6..5c88babfb47 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -57,11 +57,11 @@ void WM_keymap_init (struct bContext *C); void WM_keymap_free (struct wmKeyMap *keymap); wmKeyMapItem *WM_keymap_verify_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); + int val, int modifier, int keymodifier); void WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 5f4d3f6194a..f9b22331f37 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -115,7 +115,6 @@ struct ImBuf; #include "RNA_types.h" #include "DNA_listBase.h" -#include "BKE_utildefines.h" /* FILE_MAX */ /* exported types for WM */ #include "wm_cursors.h" diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 0074d6236db..b583c6fd7fe 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -61,7 +61,6 @@ #include "BKE_blender.h" #include "BKE_global.h" -#include "BKE_utildefines.h" #include "BIF_gl.h" #include "BIF_glutil.h" diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 2f4b2d200c3..439f528c0ef 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -810,6 +810,10 @@ if(WITH_CYCLES) cycles_kernel cycles_util cycles_subd) + + if(WITH_CYCLES_OSL) + list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl) + endif() endif() #if(UNIX) @@ -974,6 +978,10 @@ endif() list(APPEND BLENDER_SORTED_LIBS extern_xdnd) endif() + if(WITH_CYCLES_OSL) + list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl") + endif() + foreach(SORTLIB ${BLENDER_SORTED_LIBS}) set(REMLIB ${SORTLIB}) foreach(SEARCHLIB ${BLENDER_LINK_LIBS}) diff --git a/source/creator/creator.c b/source/creator/creator.c index 80981c08c5e..b3c11198403 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -68,7 +68,6 @@ #include "BLI_blenlib.h" -#include "BKE_utildefines.h" #include "BKE_blender.h" #include "BKE_context.h" #include "BKE_depsgraph.h" /* for DAG_on_visible_update */ diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 1b8f857c2cb..ed8a6cc7220 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -54,6 +54,7 @@ #include "KX_BlenderSceneConverter.h" #include "KX_PythonInit.h" #include "KX_PyConstraintBinding.h" +#include "KX_PythonMain.h" #include "RAS_GLExtensionManager.h" #include "RAS_OpenGLRasterizer.h" @@ -79,6 +80,9 @@ extern "C" { #include "DNA_windowmanager_types.h" #include "BKE_global.h" #include "BKE_report.h" + +#include "MEM_guardedalloc.h" + /* #include "BKE_screen.h" */ /* cant include this because of 'new' function name */ extern float BKE_screen_view3d_zoom_to_fac(float camzoom); @@ -121,6 +125,95 @@ static BlendFileData *load_game_data(char *filename) return bfd; } +int BL_KetsjiNextFrame(struct KX_KetsjiEngine* ketsjiengine, struct bContext *C, struct wmWindow* win, struct Scene* scene, struct ARegion *ar, + KX_BlenderKeyboardDevice* keyboarddevice, KX_BlenderMouseDevice* mousedevice, int draw_letterbox) +{ + int exitrequested; + + // first check if we want to exit + exitrequested = ketsjiengine->GetExitCode(); + + // kick the engine + bool render = ketsjiengine->NextFrame(); + + if (render) + { + if(draw_letterbox) { + // Clear screen to border color + // We do this here since we set the canvas to be within the frames. This means the engine + // itself is unaware of the extra space, so we clear the whole region for it. + glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f); + glViewport(ar->winrct.xmin, ar->winrct.ymin, + BLI_RCT_SIZE_X(&ar->winrct), BLI_RCT_SIZE_Y(&ar->winrct)); + glClear(GL_COLOR_BUFFER_BIT); + } + + // render the frame + ketsjiengine->Render(); + } + + wm_window_process_events_nosleep(); + + // test for the ESC key + //XXX while (qtest()) + while(wmEvent *event= (wmEvent *)win->queue.first) + { + short val = 0; + //unsigned short event = 0; //XXX extern_qread(&val); + + if (keyboarddevice->ConvertBlenderEvent(event->type,event->val)) + exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; + + /* Coordinate conversion... where + * should this really be? + */ + if (event->type==MOUSEMOVE) { + /* Note, not nice! XXX 2.5 event hack */ + val = event->x - ar->winrct.xmin; + mousedevice->ConvertBlenderEvent(MOUSEX, val); + + val = ar->winy - (event->y - ar->winrct.ymin) - 1; + mousedevice->ConvertBlenderEvent(MOUSEY, val); + } + else { + mousedevice->ConvertBlenderEvent(event->type,event->val); + } + + BLI_remlink(&win->queue, event); + wm_event_free(event); + } + + if(win != CTX_wm_window(C)) { + exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */ + } + return exitrequested; +} + +struct BL_KetsjiNextFrameState { + struct KX_KetsjiEngine* ketsjiengine; + struct bContext *C; + struct wmWindow* win; + struct Scene* scene; + struct ARegion *ar; + KX_BlenderKeyboardDevice* keyboarddevice; + KX_BlenderMouseDevice* mousedevice; + int draw_letterbox; +} ketsjinextframestate; + +int BL_KetsjiPyNextFrame(void *state0) +{ + BL_KetsjiNextFrameState *state = (BL_KetsjiNextFrameState *) state0; + return BL_KetsjiNextFrame( + state->ketsjiengine, + state->C, + state->win, + state->scene, + state->ar, + state->keyboarddevice, + state->mousedevice, + state->draw_letterbox); +} + extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *cam_frame, int always_use_expand_framing) { /* context values */ @@ -440,71 +533,49 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c // Could be in StartEngine set the framerate, we need the scene to do this ketsjiengine->SetAnimFrameRate(FPS); +#ifdef WITH_PYTHON + char *python_main = NULL; + pynextframestate.state = NULL; + pynextframestate.func = NULL; + python_main = KX_GetPythonMain(scene); + // the mainloop printf("\nBlender Game Engine Started\n"); - while (!exitrequested) + if (python_main) { + char *python_code = KX_GetPythonCode(blenderdata, python_main); + if (python_code) { + ketsjinextframestate.ketsjiengine = ketsjiengine; + ketsjinextframestate.C = C; + ketsjinextframestate.win = win; + ketsjinextframestate.scene = scene; + ketsjinextframestate.ar = ar; + ketsjinextframestate.keyboarddevice = keyboarddevice; + ketsjinextframestate.mousedevice = mousedevice; + ketsjinextframestate.draw_letterbox = draw_letterbox; + + pynextframestate.state = &ketsjinextframestate; + pynextframestate.func = &BL_KetsjiPyNextFrame; + printf("Yielding control to Python script '%s'...\n", python_main); + PyRun_SimpleString(python_code); + printf("Exit Python script '%s'\n", python_main); + MEM_freeN(python_code); + } + } + else +#endif /* WITH_PYTHON */ { - // first check if we want to exit - exitrequested = ketsjiengine->GetExitCode(); - - // kick the engine - bool render = ketsjiengine->NextFrame(); - - if (render) + while (!exitrequested) { - if (draw_letterbox) { - // Clear screen to border color - // We do this here since we set the canvas to be within the frames. This means the engine - // itself is unaware of the extra space, so we clear the whole region for it. - glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f); - glViewport(ar->winrct.xmin, ar->winrct.ymin, - BLI_RCT_SIZE_X(&ar->winrct), BLI_RCT_SIZE_Y(&ar->winrct)); - glClear(GL_COLOR_BUFFER_BIT); - } - - // render the frame - ketsjiengine->Render(); - } - - wm_window_process_events_nosleep(); - - // test for the ESC key - //XXX while (qtest()) - while(wmEvent *event= (wmEvent *)win->queue.first) - { - short val = 0; - //unsigned short event = 0; //XXX extern_qread(&val); - - if (keyboarddevice->ConvertBlenderEvent(event->type,event->val)) - exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; - - /* Coordinate conversion... where - * should this really be? - */ - if (event->type==MOUSEMOVE) { - /* Note, not nice! XXX 2.5 event hack */ - val = event->x - ar->winrct.xmin; - mousedevice->ConvertBlenderEvent(MOUSEX, val); - - val = ar->winy - (event->y - ar->winrct.ymin) - 1; - mousedevice->ConvertBlenderEvent(MOUSEY, val); - } - else { - mousedevice->ConvertBlenderEvent(event->type,event->val); - } - - BLI_remlink(&win->queue, event); - wm_event_free(event); - } - - if (win != CTX_wm_window(C)) { - exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */ + exitrequested = BL_KetsjiNextFrame(ketsjiengine, C, win, scene, ar, keyboarddevice, mousedevice, draw_letterbox); } } printf("Blender Game Engine Finished\n"); exitstring = ketsjiengine->GetExitString(); - gs = *(ketsjiengine->GetGlobalSettings()); +#ifdef WITH_PYTHON + if (python_main) MEM_freeN(python_main); +#endif /* WITH_PYTHON */ + gs = *(ketsjiengine->GetGlobalSettings()); // when exiting the mainloop #ifdef WITH_PYTHON diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 89a3f365140..9caa6bbf579 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -82,8 +82,7 @@ #include "BKE_text.h" #include "BLI_blenlib.h" #include "BLI_math_base.h" - -#define FILE_MAX 1024 // repeated here to avoid dependency from BKE_utildefines.h +#include "BLI_path_util.h" #include "KX_NetworkMessageActuator.h" diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 41f641b4368..6e1e8f5a8ec 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -47,6 +47,7 @@ #endif // __APPLE__ #include "KX_KetsjiEngine.h" #include "KX_PythonInit.h" +#include "KX_PythonMain.h" /********************************** * Begin Blender include block @@ -97,7 +98,6 @@ extern char datatoc_bfont_ttf[]; #include "RAS_IRasterizer.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "RNA_define.h" @@ -332,6 +332,41 @@ static BlendFileData *load_game_data(const char *progname, char *filename = NULL return bfd; } +bool GPG_NextFrame(GHOST_ISystem* system, GPG_Application *app, int &exitcode, STR_String &exitstring, GlobalSettings *gs) +{ + bool run = true; + system->processEvents(false); + system->dispatchEvents(); + app->EngineNextFrame(); + if ((exitcode = app->getExitRequested())) + { + run = false; + exitstring = app->getExitString(); + *gs = *app->getGlobalSettings(); + } + return run; +} + +struct GPG_NextFrameState { + GHOST_ISystem* system; + GPG_Application *app; + GlobalSettings *gs; +} gpg_nextframestate; + +int GPG_PyNextFrame(void *state0) +{ + GPG_NextFrameState *state = (GPG_NextFrameState *) state0; + int exitcode; + STR_String exitstring; + bool run = GPG_NextFrame(state->system, state->app, exitcode, exitstring, state->gs); + if (run) return 0; + else { + if (exitcode) + fprintf(stderr, "Exit code %d: %s\n", exitcode, exitstring.ReadPtr()); + return 1; + } +} + int main(int argc, char** argv) { int i; @@ -966,17 +1001,39 @@ int main(int argc, char** argv) // Enter main loop bool run = true; - while (run) + char *python_main = NULL; + pynextframestate.state = NULL; + pynextframestate.func = NULL; +#ifdef WITH_PYTHON + python_main = KX_GetPythonMain(scene); +#endif // WITH_PYTHON + if (python_main) { - system->processEvents(false); - system->dispatchEvents(); - app.EngineNextFrame(); - - if ((exitcode = app.getExitRequested())) + char *python_code = KX_GetPythonCode(maggie, python_main); + if (python_code) { - run = false; - exitstring = app.getExitString(); - gs = *app.getGlobalSettings(); +#ifdef WITH_PYTHON + gpg_nextframestate.system = system; + gpg_nextframestate.app = &app; + gpg_nextframestate.gs = &gs; + pynextframestate.state = &gpg_nextframestate; + pynextframestate.func = &GPG_PyNextFrame; + + printf("Yielding control to Python script '%s'...\n", python_main); + PyRun_SimpleString(python_code); + printf("Exit Python script '%s'\n", python_main); +#endif // WITH_PYTHON + MEM_freeN(python_code); + } + else { + fprintf(stderr, "ERROR: cannot yield control to Python: no Python text data block named '%s'\n", python_main); + } + } + else + { + while (run) + { + run = GPG_NextFrame(system, &app, exitcode, exitstring, &gs); } } app.StopGameEngine(); @@ -986,6 +1043,7 @@ int main(int argc, char** argv) system->removeEventConsumer(&app); BLO_blendfiledata_free(bfd); + if (python_main) MEM_freeN(python_main); } } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME); } diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 4b3426e0784..269311b7e00 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -107,6 +107,7 @@ set(SRC KX_PyMath.cpp KX_PythonInit.cpp KX_PythonInitTypes.cpp + KX_PythonMain.cpp KX_PythonSeq.cpp KX_RadarSensor.cpp KX_RayCast.cpp @@ -189,6 +190,7 @@ set(SRC KX_PyMath.h KX_PythonInit.h KX_PythonInitTypes.h + KX_PythonMain.h KX_PythonSeq.h KX_RadarSensor.h KX_RayCast.h diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 581b3712f97..7d29a20d1a2 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -133,7 +133,6 @@ extern "C" { #include "PHY_IPhysicsEnvironment.h" #include "BKE_main.h" -#include "BKE_utildefines.h" #include "BKE_global.h" #include "BLI_blenlib.h" #include "GPU_material.h" @@ -811,6 +810,23 @@ static PyObject *gLibList(PyObject*, PyObject* args) return list; } +struct PyNextFrameState pynextframestate; +static PyObject *gPyNextFrame(PyObject *) +{ + if (pynextframestate.func == NULL) Py_RETURN_NONE; + if (pynextframestate.state == NULL) Py_RETURN_NONE; //should never happen; raise exception instead? + + if (pynextframestate.func(pynextframestate.state)) //nonzero = stop + { + Py_RETURN_TRUE; + } + else // 0 = go on + { + Py_RETURN_FALSE; + } +} + + static struct PyMethodDef game_methods[] = { {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc}, {"startGame", (PyCFunction)gPyStartGame, METH_VARARGS, (const char *)gPyStartGame_doc}, @@ -840,7 +856,7 @@ static struct PyMethodDef game_methods[] = { {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"}, {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"}, {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"}, - + {"NextFrame", (PyCFunction)gPyNextFrame, METH_NOARGS, (const char *)"Render next frame (if Python has control)"}, /* library functions */ {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""}, {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""}, diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 866681b9da7..1500dd97ae1 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -70,6 +70,16 @@ class KX_Scene; void KX_SetActiveScene(class KX_Scene* scene); class KX_Scene* KX_GetActiveScene(); class KX_KetsjiEngine* KX_GetActiveEngine(); + +typedef int (*PyNextFrameFunc)(void *); +struct PyNextFrameState { + //state: can be either a GPG_NextFrameState or a BL_KetsjiNextFrameState + void *state; + //func: can be either GPG_PyNextFrame or BL_KetsjiPyNextFrame + PyNextFrameFunc func; +}; +extern struct PyNextFrameState pynextframestate; + #include "MT_Vector3.h" void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color); diff --git a/source/gameengine/Ketsji/KX_PythonMain.cpp b/source/gameengine/Ketsji/KX_PythonMain.cpp new file mode 100644 index 00000000000..d5550ce4380 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.cpp @@ -0,0 +1,77 @@ +/* + * $Id: KX_PythonMain.cpp 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +/** \file gameengine/Ketsji/KX_KetsjiPythonMain.cpp + * \ingroup ketsji + */ + +#include "KX_PythonMain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "MEM_guardedalloc.h" + +#include "BLI_string.h" +#include "BLI_listbase.h" + +#include "BKE_text.h" +#include "BKE_main.h" +#include "BKE_idprop.h" + + +#ifdef __cplusplus +} +#endif + +extern "C" char *KX_GetPythonMain(struct Scene *scene) +{ + /* examine custom scene properties */ + if (scene->id.properties) { + IDProperty *item = IDP_GetPropertyTypeFromGroup(scene->id.properties, "__main__", IDP_STRING); + if (item) { + return BLI_strdup(IDP_String(item)); + } + } + + return NULL; +} + +extern "C" char *KX_GetPythonCode(Main *bmain, char *python_main) +{ + Text *text; + + if ((text = (Text *)BLI_findstring(&bmain->text, python_main, offsetof(ID, name) + 2))) { + return txt_to_buf(text); + } + + return NULL; +} diff --git a/source/gameengine/Ketsji/KX_PythonMain.h b/source/gameengine/Ketsji/KX_PythonMain.h new file mode 100644 index 00000000000..1460ea2ca96 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.h @@ -0,0 +1,41 @@ +/* + * $Id: KX_PythonMain.h 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file KX_PythonMain.h + * \ingroup ketsji + */ + +#ifndef __KX_PYTHON_MAIN +#define __KX_PYTHON_MAIN + +#include "BKE_main.h" +#include "DNA_scene_types.h" +extern "C" char *KX_GetPythonMain(struct Scene* scene); +extern "C" char *KX_GetPythonCode(struct Main *main, char *python_main); +#endif