Cycles: Pass Blender's C++ RNA structures by reference

This way we avoid passing structures which could be up to
few hundred bytes by value to the utility functions.

Ideally we'll also have to add `const` qualifier in majority
of the calls, but C++ RNA does not allow us to do that because
it does not know if some function modifies contents or not.
This commit is contained in:
Sergey Sharybin 2016-01-30 14:18:29 +01:00
parent 0e4e1993e6
commit 74c7707e8c
14 changed files with 496 additions and 246 deletions

View File

@ -77,7 +77,8 @@ struct BlenderCamera {
Transform matrix;
};
static void blender_camera_init(BlenderCamera *bcam, BL::RenderSettings b_render)
static void blender_camera_init(BlenderCamera *bcam,
BL::RenderSettings& b_render)
{
memset(bcam, 0, sizeof(BlenderCamera));
@ -107,7 +108,9 @@ static void blender_camera_init(BlenderCamera *bcam, BL::RenderSettings b_render
bcam->pixelaspect.y = b_render.pixel_aspect_y();
}
static float blender_camera_focal_distance(BL::RenderEngine b_engine, BL::Object b_ob, BL::Camera b_camera)
static float blender_camera_focal_distance(BL::RenderEngine& b_engine,
BL::Object& b_ob,
BL::Camera& b_camera)
{
BL::Object b_dof_object = b_camera.dof_object();
@ -124,7 +127,10 @@ static float blender_camera_focal_distance(BL::RenderEngine b_engine, BL::Object
return fabsf(dot(view_dir, dof_dir));
}
static void blender_camera_from_object(BlenderCamera *bcam, BL::RenderEngine b_engine, BL::Object b_ob, bool skip_panorama = false)
static void blender_camera_from_object(BlenderCamera *bcam,
BL::RenderEngine& b_engine,
BL::Object& b_ob,
bool skip_panorama = false)
{
BL::ID b_ob_data = b_ob.data();
@ -439,7 +445,9 @@ static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int
/* Sync Render Camera */
void BlenderSync::sync_camera(BL::RenderSettings b_render, BL::Object b_override, int width, int height)
void BlenderSync::sync_camera(BL::RenderSettings& b_render,
BL::Object& b_override,
int width, int height)
{
BlenderCamera bcam;
blender_camera_init(&bcam, b_render);
@ -448,9 +456,9 @@ void BlenderSync::sync_camera(BL::RenderSettings b_render, BL::Object b_override
bcam.pixelaspect.x = b_render.pixel_aspect_x();
bcam.pixelaspect.y = b_render.pixel_aspect_y();
bcam.shuttertime = b_render.motion_blur_shutter();
curvemapping_to_array(b_render.motion_blur_shutter_curve(),
bcam.shutter_curve,
RAMP_TABLE_SIZE);
BL::CurveMapping b_shutter_curve(b_render.motion_blur_shutter_curve());
curvemapping_to_array(b_shutter_curve, bcam.shutter_curve, RAMP_TABLE_SIZE);
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
switch(RNA_enum_get(&cscene, "motion_blur_position")) {
@ -507,8 +515,8 @@ void BlenderSync::sync_camera(BL::RenderSettings b_render, BL::Object b_override
blender_camera_sync(cam, &bcam, width, height);
}
void BlenderSync::sync_camera_motion(BL::RenderSettings b_render,
BL::Object b_ob,
void BlenderSync::sync_camera_motion(BL::RenderSettings& b_render,
BL::Object& b_ob,
int width, int height,
float motion_time)
{
@ -562,19 +570,32 @@ void BlenderSync::sync_camera_motion(BL::RenderSettings b_render,
/* Sync 3D View Camera */
static void blender_camera_view_subset(BL::RenderEngine b_engine, BL::RenderSettings b_render, BL::Scene b_scene, BL::Object b_ob, BL::SpaceView3D b_v3d,
BL::RegionView3D b_rv3d, int width, int height, BoundBox2D *view_box, BoundBox2D *cam_box);
static void blender_camera_view_subset(BL::RenderEngine& b_engine,
BL::RenderSettings& b_render,
BL::Scene& b_scene,
BL::Object& b_ob,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height,
BoundBox2D *view_box,
BoundBox2D *cam_box);
static void blender_camera_from_view(BlenderCamera *bcam, BL::RenderEngine b_engine, BL::Scene b_scene, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height, bool skip_panorama = false)
static void blender_camera_from_view(BlenderCamera *bcam,
BL::RenderEngine& b_engine,
BL::Scene& b_scene,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height,
bool skip_panorama = false)
{
/* 3d view parameters */
bcam->nearclip = b_v3d.clip_start();
bcam->farclip = b_v3d.clip_end();
bcam->lens = b_v3d.lens();
bcam->shuttertime = b_scene.render().motion_blur_shutter();
curvemapping_to_array(b_scene.render().motion_blur_shutter_curve(),
bcam->shutter_curve,
RAMP_TABLE_SIZE);
BL::CurveMapping b_shutter_curve(b_scene.render().motion_blur_shutter_curve());
curvemapping_to_array(b_shutter_curve, bcam->shutter_curve, RAMP_TABLE_SIZE);
if(b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_CAMERA) {
/* camera view */
@ -587,8 +608,16 @@ static void blender_camera_from_view(BlenderCamera *bcam, BL::RenderEngine b_eng
/* in panorama camera view, we map viewplane to camera border */
BoundBox2D view_box, cam_box;
blender_camera_view_subset(b_engine, b_scene.render(), b_scene, b_ob, b_v3d, b_rv3d, width, height,
&view_box, &cam_box);
BL::RenderSettings b_render_settings(b_scene.render());
blender_camera_view_subset(b_engine,
b_render_settings,
b_scene,
b_ob,
b_v3d,
b_rv3d,
width, height,
&view_box,
&cam_box);
bcam->pano_viewplane = view_box.make_relative_to(cam_box);
}
@ -625,8 +654,15 @@ static void blender_camera_from_view(BlenderCamera *bcam, BL::RenderEngine b_eng
bcam->matrix = transform_inverse(get_transform(b_rv3d.view_matrix()));
}
static void blender_camera_view_subset(BL::RenderEngine b_engine, BL::RenderSettings b_render, BL::Scene b_scene, BL::Object b_ob, BL::SpaceView3D b_v3d,
BL::RegionView3D b_rv3d, int width, int height, BoundBox2D *view_box, BoundBox2D *cam_box)
static void blender_camera_view_subset(BL::RenderEngine& b_engine,
BL::RenderSettings& b_render,
BL::Scene& b_scene,
BL::Object& b_ob,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height,
BoundBox2D *view_box,
BoundBox2D *cam_box)
{
BoundBox2D cam, view;
float view_aspect, cam_aspect, sensor_size;
@ -652,12 +688,12 @@ static void blender_camera_view_subset(BL::RenderEngine b_engine, BL::RenderSett
*cam_box = cam * (1.0f/cam_aspect);
}
static void blender_camera_border_subset(BL::RenderEngine b_engine,
BL::RenderSettings b_render,
BL::Scene b_scene,
BL::SpaceView3D b_v3d,
BL::RegionView3D b_rv3d,
BL::Object b_ob,
static void blender_camera_border_subset(BL::RenderEngine& b_engine,
BL::RenderSettings& b_render,
BL::Scene& b_scene,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
BL::Object& b_ob,
int width, int height,
const BoundBox2D &border,
BoundBox2D *result)
@ -672,8 +708,13 @@ static void blender_camera_border_subset(BL::RenderEngine b_engine,
*result = cam_box.subset(border);
}
static void blender_camera_border(BlenderCamera *bcam, BL::RenderEngine b_engine, BL::RenderSettings b_render, BL::Scene b_scene, BL::SpaceView3D b_v3d,
BL::RegionView3D b_rv3d, int width, int height)
static void blender_camera_border(BlenderCamera *bcam,
BL::RenderEngine& b_engine,
BL::RenderSettings& b_render,
BL::Scene& b_scene,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height)
{
bool is_camera_view;
@ -733,17 +774,34 @@ static void blender_camera_border(BlenderCamera *bcam, BL::RenderEngine b_engine
bcam->border.clamp();
}
void BlenderSync::sync_view(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height)
void BlenderSync::sync_view(BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height)
{
BlenderCamera bcam;
blender_camera_init(&bcam, b_scene.render());
blender_camera_from_view(&bcam, b_engine, b_scene, b_v3d, b_rv3d, width, height);
blender_camera_border(&bcam, b_engine, b_scene.render(), b_scene, b_v3d, b_rv3d, width, height);
BL::RenderSettings b_render_settings(b_scene.render());
blender_camera_init(&bcam, b_render_settings);
blender_camera_from_view(&bcam,
b_engine,
b_scene,
b_v3d,
b_rv3d,
width, height);
blender_camera_border(&bcam,
b_engine,
b_render_settings,
b_scene,
b_v3d,
b_rv3d,
width, height);
blender_camera_sync(scene->camera, &bcam, width, height);
}
BufferParams BlenderSync::get_buffer_params(BL::RenderSettings b_render, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, Camera *cam, int width, int height)
BufferParams BlenderSync::get_buffer_params(BL::RenderSettings& b_render,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
Camera *cam,
int width, int height)
{
BufferParams params;
bool use_border = false;

View File

@ -856,7 +856,11 @@ void BlenderSync::sync_curve_settings()
curve_system_manager->tag_update(scene);
}
void BlenderSync::sync_curves(Mesh *mesh, BL::Mesh b_mesh, BL::Object b_ob, bool motion, int time_index)
void BlenderSync::sync_curves(Mesh *mesh,
BL::Mesh& b_mesh,
BL::Object& b_ob,
bool motion,
int time_index)
{
if(!motion) {
/* Clear stored curve data */

View File

@ -80,7 +80,9 @@ inline void face_split_tri_indices(const int num_verts,
/* Tangent Space */
struct MikkUserData {
MikkUserData(const BL::Mesh mesh_, BL::MeshTextureFaceLayer *layer_, int num_faces_)
MikkUserData(const BL::Mesh& mesh_,
BL::MeshTextureFaceLayer *layer_,
int num_faces_)
: mesh(mesh_), layer(layer_), num_faces(num_faces_)
{
tangent.resize(num_faces*4);
@ -182,7 +184,7 @@ static void mikk_set_tangent_space(const SMikkTSpaceContext *context, const floa
userdata->tangent[face*4 + vert] = make_float4(T[0], T[1], T[2], sign);
}
static void mikk_compute_tangents(BL::Mesh b_mesh,
static void mikk_compute_tangents(BL::Mesh& b_mesh,
BL::MeshTextureFaceLayer *b_layer,
Mesh *mesh,
const vector<int>& nverts,
@ -280,7 +282,11 @@ static void mikk_compute_tangents(BL::Mesh b_mesh,
/* Create Volume Attribute */
static void create_mesh_volume_attribute(BL::Object b_ob, Mesh *mesh, ImageManager *image_manager, AttributeStandard std, float frame)
static void create_mesh_volume_attribute(BL::Object& b_ob,
Mesh *mesh,
ImageManager *image_manager,
AttributeStandard std,
float frame)
{
BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
@ -305,7 +311,10 @@ static void create_mesh_volume_attribute(BL::Object b_ob, Mesh *mesh, ImageManag
true);
}
static void create_mesh_volume_attributes(Scene *scene, BL::Object b_ob, Mesh *mesh, float frame)
static void create_mesh_volume_attributes(Scene *scene,
BL::Object& b_ob,
Mesh *mesh,
float frame)
{
/* for smoke volume rendering */
if(mesh->need_attribute(scene, ATTR_STD_VOLUME_DENSITY))
@ -323,7 +332,7 @@ static void create_mesh_volume_attributes(Scene *scene, BL::Object b_ob, Mesh *m
/* Create vertex color attributes. */
static void attr_create_vertex_color(Scene *scene,
Mesh *mesh,
BL::Mesh b_mesh,
BL::Mesh& b_mesh,
const vector<int>& nverts,
const vector<int>& face_flags)
{
@ -370,7 +379,7 @@ static void attr_create_vertex_color(Scene *scene,
/* Create uv map attributes. */
static void attr_create_uv_map(Scene *scene,
Mesh *mesh,
BL::Mesh b_mesh,
BL::Mesh& b_mesh,
const vector<int>& nverts,
const vector<int>& face_flags)
{
@ -455,7 +464,7 @@ static void attr_create_uv_map(Scene *scene,
/* Create vertex pointiness attributes. */
static void attr_create_pointiness(Scene *scene,
Mesh *mesh,
BL::Mesh b_mesh)
BL::Mesh& b_mesh)
{
if(mesh->need_attribute(scene, ATTR_STD_POINTINESS)) {
const int numverts = b_mesh.vertices.length();
@ -519,7 +528,10 @@ static void attr_create_pointiness(Scene *scene,
/* Create Mesh */
static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<uint>& used_shaders)
static void create_mesh(Scene *scene,
Mesh *mesh,
BL::Mesh& b_mesh,
const vector<uint>& used_shaders)
{
/* count vertices and faces */
int numverts = b_mesh.vertices.length();
@ -641,7 +653,11 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
}
}
static void create_subd_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, PointerRNA *cmesh, const vector<uint>& used_shaders)
static void create_subd_mesh(Scene *scene,
Mesh *mesh,
BL::Mesh& b_mesh,
PointerRNA *cmesh,
const vector<uint>& used_shaders)
{
/* create subd mesh */
SubdMesh sdmesh;
@ -685,7 +701,9 @@ static void create_subd_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, PointerR
/* Sync */
Mesh *BlenderSync::sync_mesh(BL::Object b_ob, bool object_updated, bool hide_tris)
Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
bool object_updated,
bool hide_tris)
{
/* When viewport display is not needed during render we can force some
* caches to be releases from blender side in order to reduce peak memory
@ -705,10 +723,13 @@ Mesh *BlenderSync::sync_mesh(BL::Object b_ob, bool object_updated, bool hide_tri
BL::Object::material_slots_iterator slot;
for(b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
if(material_override)
if(material_override) {
find_shader(material_override, used_shaders, scene->default_surface);
else
find_shader(slot->material(), used_shaders, scene->default_surface);
}
else {
BL::ID b_material(slot->material());
find_shader(b_material, used_shaders, scene->default_surface);
}
}
if(used_shaders.size() == 0) {
@ -838,7 +859,9 @@ Mesh *BlenderSync::sync_mesh(BL::Object b_ob, bool object_updated, bool hide_tri
return mesh;
}
void BlenderSync::sync_mesh_motion(BL::Object b_ob, Object *object, float motion_time)
void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
Object *object,
float motion_time)
{
/* ensure we only sync instanced meshes once */
Mesh *mesh = object->mesh;

View File

@ -36,7 +36,7 @@ CCL_NAMESPACE_BEGIN
/* Utilities */
bool BlenderSync::BKE_object_is_modified(BL::Object b_ob)
bool BlenderSync::BKE_object_is_modified(BL::Object& b_ob)
{
/* test if we can instance or if the object is modified */
if(b_ob.type() == BL::Object::type_META) {
@ -58,7 +58,7 @@ bool BlenderSync::BKE_object_is_modified(BL::Object b_ob)
return false;
}
bool BlenderSync::object_is_mesh(BL::Object b_ob)
bool BlenderSync::object_is_mesh(BL::Object& b_ob)
{
BL::ID b_ob_data = b_ob.data();
@ -66,14 +66,14 @@ bool BlenderSync::object_is_mesh(BL::Object b_ob)
b_ob_data.is_a(&RNA_Curve) || b_ob_data.is_a(&RNA_MetaBall)));
}
bool BlenderSync::object_is_light(BL::Object b_ob)
bool BlenderSync::object_is_light(BL::Object& b_ob)
{
BL::ID b_ob_data = b_ob.data();
return (b_ob_data && b_ob_data.is_a(&RNA_Lamp));
}
static uint object_ray_visibility(BL::Object b_ob)
static uint object_ray_visibility(BL::Object& b_ob)
{
PointerRNA cvisibility = RNA_pointer_get(&b_ob.ptr, "cycles_visibility");
uint flag = 0;
@ -90,7 +90,11 @@ static uint object_ray_visibility(BL::Object b_ob)
/* Light */
void BlenderSync::sync_light(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::Object b_ob, Transform& tfm, bool *use_portal)
void BlenderSync::sync_light(BL::Object& b_parent,
int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
BL::Object& b_ob,
Transform& tfm,
bool *use_portal)
{
/* test if we need to sync */
Light *light;
@ -239,7 +243,7 @@ void BlenderSync::sync_background_light(bool use_portal)
* to reduce number of objects which are wrongly considered visible.
*/
static bool object_boundbox_clip(Scene *scene,
BL::Object b_ob,
BL::Object& b_ob,
Transform& tfm,
float margin)
{
@ -275,9 +279,9 @@ static bool object_boundbox_clip(Scene *scene,
return true;
}
Object *BlenderSync::sync_object(BL::Object b_parent,
Object *BlenderSync::sync_object(BL::Object& b_parent,
int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
BL::DupliObject b_dupli_ob,
BL::DupliObject& b_dupli_ob,
Transform& tfm,
uint layer_flag,
float motion_time,
@ -439,7 +443,8 @@ Object *BlenderSync::sync_object(BL::Object b_parent,
return object;
}
static bool object_render_hide_original(BL::Object::type_enum ob_type, BL::Object::dupli_type_enum dupli_type)
static bool object_render_hide_original(BL::Object::type_enum ob_type,
BL::Object::dupli_type_enum dupli_type)
{
/* metaball exception, they duplicate self */
if(ob_type == BL::Object::type_META)
@ -450,7 +455,10 @@ static bool object_render_hide_original(BL::Object::type_enum ob_type, BL::Objec
dupli_type == BL::Object::dupli_type_FRAMES);
}
static bool object_render_hide(BL::Object b_ob, bool top_level, bool parent_hide, bool& hide_triangles)
static bool object_render_hide(BL::Object& b_ob,
bool top_level,
bool parent_hide,
bool& hide_triangles)
{
/* check if we should render or hide particle emitter */
BL::Object::particle_systems_iterator b_psys;
@ -507,7 +515,7 @@ static bool object_render_hide(BL::Object b_ob, bool top_level, bool parent_hide
}
}
static bool object_render_hide_duplis(BL::Object b_ob)
static bool object_render_hide_duplis(BL::Object& b_ob)
{
BL::Object parent = b_ob.parent();
@ -516,7 +524,7 @@ static bool object_render_hide_duplis(BL::Object b_ob)
/* Object Loop */
void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, float motion_time)
void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time)
{
/* layer data */
uint scene_layer = render_layer.scene_layer;
@ -631,9 +639,10 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, float motion_time)
if(!object_render_hide(b_ob, true, true, hide_tris)) {
/* object itself */
Transform tfm = get_transform(b_ob.matrix_world());
BL::DupliObject b_empty_dupli_ob(PointerRNA_NULL);
sync_object(b_ob,
NULL,
PointerRNA_NULL,
b_empty_dupli_ob,
tfm,
ob_layer,
motion_time,
@ -668,9 +677,9 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, float motion_time)
mesh_motion_synced.clear();
}
void BlenderSync::sync_motion(BL::RenderSettings b_render,
BL::SpaceView3D b_v3d,
BL::Object b_override,
void BlenderSync::sync_motion(BL::RenderSettings& b_render,
BL::SpaceView3D& b_v3d,
BL::Object& b_override,
int width, int height,
void **python_thread_state)
{

View File

@ -27,7 +27,9 @@ CCL_NAMESPACE_BEGIN
/* Utilities */
bool BlenderSync::sync_dupli_particle(BL::Object b_ob, BL::DupliObject b_dup, Object *object)
bool BlenderSync::sync_dupli_particle(BL::Object& b_ob,
BL::DupliObject& b_dup,
Object *object)
{
/* test if this dupli was generated from a particle sytem */
BL::ParticleSystem b_psys = b_dup.particle_system();

View File

@ -44,10 +44,18 @@ CCL_NAMESPACE_BEGIN
bool BlenderSession::headless = false;
BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_,
BL::BlendData b_data_, BL::Scene b_scene_)
: b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_render(b_engine_.render()), b_scene(b_scene_),
b_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL), python_thread_state(NULL)
BlenderSession::BlenderSession(BL::RenderEngine& b_engine,
BL::UserPreferences& b_userpref,
BL::BlendData& b_data,
BL::Scene& b_scene)
: b_engine(b_engine),
b_userpref(b_userpref),
b_data(b_data),
b_render(b_engine.render()),
b_scene(b_scene),
b_v3d(PointerRNA_NULL),
b_rv3d(PointerRNA_NULL),
python_thread_state(NULL)
{
/* offline render */
@ -59,16 +67,26 @@ BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b
start_resize_time = 0.0;
}
BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_,
BL::BlendData b_data_, BL::Scene b_scene_,
BL::SpaceView3D b_v3d_, BL::RegionView3D b_rv3d_, int width_, int height_)
: b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_render(b_scene_.render()), b_scene(b_scene_),
b_v3d(b_v3d_), b_rv3d(b_rv3d_), python_thread_state(NULL)
BlenderSession::BlenderSession(BL::RenderEngine& b_engine,
BL::UserPreferences& b_userpref,
BL::BlendData& b_data,
BL::Scene& b_scene,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height)
: b_engine(b_engine),
b_userpref(b_userpref),
b_data(b_data),
b_render(b_scene.render()),
b_scene(b_scene),
b_v3d(b_v3d),
b_rv3d(b_rv3d),
width(width),
height(height),
python_thread_state(NULL)
{
/* 3d view render */
width = width_;
height = height_;
background = false;
last_redraw_time = 0.0;
start_resize_time = 0.0;
@ -117,14 +135,14 @@ void BlenderSession::create_session()
/* create sync */
sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress, is_cpu);
BL::Object b_camera_override(b_engine.camera_override());
if(b_v3d) {
if(session_pause == false) {
/* full data sync */
sync->sync_view(b_v3d, b_rv3d, width, height);
sync->sync_data(b_render,
b_v3d,
b_engine.camera_override(),
b_camera_override,
width, height,
&python_thread_state,
b_rlay_name.c_str());
@ -135,7 +153,7 @@ void BlenderSession::create_session()
* do some basic syncing here, no objects or materials for speed */
sync->sync_render_layers(b_v3d, NULL);
sync->sync_integrator();
sync->sync_camera(b_render, b_engine.camera_override(), width, height);
sync->sync_camera(b_render, b_camera_override, width, height);
}
/* set buffer parameters */
@ -145,7 +163,7 @@ void BlenderSession::create_session()
b_engine.use_highlight_tiles(session_params.progressive_refine == false);
}
void BlenderSession::reset_session(BL::BlendData b_data_, BL::Scene b_scene_)
void BlenderSession::reset_session(BL::BlendData& b_data_, BL::Scene& b_scene_)
{
b_data = b_data_;
b_render = b_engine.render();
@ -188,11 +206,18 @@ void BlenderSession::reset_session(BL::BlendData b_data_, BL::Scene b_scene_)
/* for final render we will do full data sync per render layer, only
* do some basic syncing here, no objects or materials for speed */
BL::Object b_camera_override(b_engine.camera_override());
sync->sync_render_layers(b_v3d, NULL);
sync->sync_integrator();
sync->sync_camera(b_render, b_engine.camera_override(), width, height);
sync->sync_camera(b_render, b_camera_override, width, height);
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, PointerRNA_NULL, PointerRNA_NULL, scene->camera, width, height);
BL::SpaceView3D b_null_space_view3d(PointerRNA_NULL);
BL::RegionView3D b_null_region_view3d(PointerRNA_NULL);
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render,
b_null_space_view3d,
b_null_region_view3d,
scene->camera,
width, height);
session->reset(buffer_params, session_params.samples);
b_engine.use_highlight_tiles(session_params.progressive_refine == false);
@ -209,7 +234,7 @@ void BlenderSession::free_session()
delete session;
}
static PassType get_pass_type(BL::RenderPass b_pass)
static PassType get_pass_type(BL::RenderPass& b_pass)
{
switch(b_pass.type()) {
case BL::RenderPass::type_COMBINED:
@ -333,12 +358,19 @@ static ShaderEvalType get_shader_type(const string& pass_type)
return SHADER_EVAL_BAKE;
}
static BL::RenderResult begin_render_result(BL::RenderEngine b_engine, int x, int y, int w, int h, const char *layername, const char *viewname)
static BL::RenderResult begin_render_result(BL::RenderEngine& b_engine,
int x, int y,
int w, int h,
const char *layername,
const char *viewname)
{
return b_engine.begin_result(x, y, w, h, layername, viewname);
}
static void end_render_result(BL::RenderEngine b_engine, BL::RenderResult b_rr, bool cancel, bool do_merge_results)
static void end_render_result(BL::RenderEngine& b_engine,
BL::RenderResult& b_rr,
bool cancel,
bool do_merge_results)
{
b_engine.end_result(b_rr, (int)cancel, (int)do_merge_results);
}
@ -469,10 +501,11 @@ void BlenderSession::render()
b_engine.active_view_set(b_rview_name.c_str());
/* update scene */
sync->sync_camera(b_render, b_engine.camera_override(), width, height);
BL::Object b_camera_override(b_engine.camera_override());
sync->sync_camera(b_render, b_camera_override, width, height);
sync->sync_data(b_render,
b_v3d,
b_engine.camera_override(),
b_camera_override,
width, height,
&python_thread_state,
b_rlay_name.c_str());
@ -520,7 +553,10 @@ void BlenderSession::render()
sync = NULL;
}
static void populate_bake_data(BakeData *data, const int object_id, BL::BakePixel pixel_array, const int num_pixels)
static void populate_bake_data(BakeData *data, const
int object_id,
BL::BakePixel& pixel_array,
const int num_pixels)
{
BL::BakePixel bp = pixel_array;
@ -563,11 +599,11 @@ static int bake_pass_filter_get(const int pass_filter)
return flag;
}
void BlenderSession::bake(BL::Object b_object,
void BlenderSession::bake(BL::Object& b_object,
const string& pass_type,
const int pass_filter,
const int object_id,
BL::BakePixel pixel_array,
BL::BakePixel& pixel_array,
const size_t num_pixels,
const int /*depth*/,
float result[])
@ -603,10 +639,11 @@ void BlenderSession::bake(BL::Object b_object,
scene->integrator->tag_update(scene);
/* update scene */
sync->sync_camera(b_render, b_engine.camera_override(), width, height);
BL::Object b_camera_override(b_engine.camera_override());
sync->sync_camera(b_render, b_camera_override, width, height);
sync->sync_data(b_render,
b_v3d,
b_engine.camera_override(),
b_camera_override,
width, height,
&python_thread_state,
b_rlay_name.c_str());
@ -657,7 +694,10 @@ void BlenderSession::bake(BL::Object b_object,
sync = NULL;
}
void BlenderSession::do_write_update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile, bool do_update_only)
void BlenderSession::do_write_update_render_result(BL::RenderResult& b_rr,
BL::RenderLayer& b_rlay,
RenderTile& rtile,
bool do_update_only)
{
RenderBuffers *buffers = rtile.buffers;
@ -699,12 +739,16 @@ void BlenderSession::do_write_update_render_result(BL::RenderResult b_rr, BL::Re
b_engine.update_result(b_rr);
}
void BlenderSession::write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile)
void BlenderSession::write_render_result(BL::RenderResult& b_rr,
BL::RenderLayer& b_rlay,
RenderTile& rtile)
{
do_write_update_render_result(b_rr, b_rlay, rtile, false);
}
void BlenderSession::update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile)
void BlenderSession::update_render_result(BL::RenderResult& b_rr,
BL::RenderLayer& b_rlay,
RenderTile& rtile)
{
do_write_update_render_result(b_rr, b_rlay, rtile, true);
}
@ -751,9 +795,10 @@ void BlenderSession::synchronize()
}
/* data and camera synchronize */
BL::Object b_camera_override(b_engine.camera_override());
sync->sync_data(b_render,
b_v3d,
b_engine.camera_override(),
b_camera_override,
width, height,
&python_thread_state,
b_rlay_name.c_str());
@ -761,7 +806,7 @@ void BlenderSession::synchronize()
if(b_rv3d)
sync->sync_view(b_v3d, b_rv3d, width, height);
else
sync->sync_camera(b_render, b_engine.camera_override(), width, height);
sync->sync_camera(b_render, b_camera_override, width, height);
/* unlock */
session->scene->mutex.unlock();

View File

@ -33,11 +33,18 @@ class RenderTile;
class BlenderSession {
public:
BlenderSession(BL::RenderEngine b_engine, BL::UserPreferences b_userpref,
BL::BlendData b_data, BL::Scene b_scene);
BlenderSession(BL::RenderEngine b_engine, BL::UserPreferences b_userpref,
BL::BlendData b_data, BL::Scene b_scene,
BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height);
BlenderSession(BL::RenderEngine& b_engine,
BL::UserPreferences& b_userpref,
BL::BlendData& b_data,
BL::Scene& b_scene);
BlenderSession(BL::RenderEngine& b_engine,
BL::UserPreferences& b_userpref,
BL::BlendData& b_data,
BL::Scene& b_scene,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height);
~BlenderSession();
@ -47,26 +54,31 @@ public:
void create_session();
void free_session();
void reset_session(BL::BlendData b_data, BL::Scene b_scene);
void reset_session(BL::BlendData& b_data,
BL::Scene& b_scene);
/* offline render */
void render();
void bake(BL::Object b_object,
void bake(BL::Object& b_object,
const string& pass_type,
const int custom_flag,
const int object_id,
BL::BakePixel pixel_array,
BL::BakePixel& pixel_array,
const size_t num_pixels,
const int depth,
float pixels[]);
void write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile);
void write_render_result(BL::RenderResult& b_rr,
BL::RenderLayer& b_rlay,
RenderTile& rtile);
void write_render_tile(RenderTile& rtile);
/* update functions are used to update display buffer only after sample was rendered
* only needed for better visual feedback */
void update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile);
void update_render_result(BL::RenderResult& b_rr,
BL::RenderLayer& b_rlay,
RenderTile& rtile);
void update_render_tile(RenderTile& rtile);
/* interactive updates */
@ -109,7 +121,10 @@ public:
void *python_thread_state;
protected:
void do_write_update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile, bool do_update_only);
void do_write_update_render_result(BL::RenderResult& b_rr,
BL::RenderLayer& b_rlay,
RenderTile& rtile,
bool do_update_only);
void do_write_update_render_tile(RenderTile& rtile, bool do_update_only);
int builtin_image_frame(const string &builtin_name);

View File

@ -36,7 +36,9 @@ typedef map<std::string, ProxyNode*> ProxyMap;
/* Find */
void BlenderSync::find_shader(BL::ID id, vector<uint>& used_shaders, int default_shader)
void BlenderSync::find_shader(BL::ID& id,
vector<uint>& used_shaders,
int default_shader)
{
Shader *shader = (id)? shader_map.find(id): scene->shaders[default_shader];
@ -51,7 +53,7 @@ void BlenderSync::find_shader(BL::ID id, vector<uint>& used_shaders, int default
/* Graph */
static BL::NodeSocket get_node_output(BL::Node b_node, const string& name)
static BL::NodeSocket get_node_output(BL::Node& b_node, const string& name)
{
BL::Node::outputs_iterator b_out;
@ -64,7 +66,7 @@ static BL::NodeSocket get_node_output(BL::Node b_node, const string& name)
return *b_out;
}
static float3 get_node_output_rgba(BL::Node b_node, const string& name)
static float3 get_node_output_rgba(BL::Node& b_node, const string& name)
{
BL::NodeSocket b_sock = get_node_output(b_node, name);
float value[4];
@ -72,13 +74,13 @@ static float3 get_node_output_rgba(BL::Node b_node, const string& name)
return make_float3(value[0], value[1], value[2]);
}
static float get_node_output_value(BL::Node b_node, const string& name)
static float get_node_output_value(BL::Node& b_node, const string& name)
{
BL::NodeSocket b_sock = get_node_output(b_node, name);
return RNA_float_get(&b_sock.ptr, "default_value");
}
static float3 get_node_output_vector(BL::Node b_node, const string& name)
static float3 get_node_output_vector(BL::Node& b_node, const string& name)
{
BL::NodeSocket b_sock = get_node_output(b_node, name);
float value[3];
@ -86,7 +88,7 @@ static float3 get_node_output_vector(BL::Node b_node, const string& name)
return make_float3(value[0], value[1], value[2]);
}
static ShaderSocketType convert_socket_type(BL::NodeSocket b_socket)
static ShaderSocketType convert_socket_type(BL::NodeSocket& b_socket)
{
switch(b_socket.type()) {
case BL::NodeSocket::type_VALUE:
@ -109,7 +111,7 @@ static ShaderSocketType convert_socket_type(BL::NodeSocket b_socket)
#ifdef WITH_OSL
static ShaderSocketType convert_osl_socket_type(OSL::OSLQuery& query,
BL::NodeSocket b_socket)
BL::NodeSocket& b_socket)
{
ShaderSocketType socket_type = convert_socket_type(b_socket);
#if OSL_LIBRARY_VERSION_CODE < 10701
@ -133,7 +135,10 @@ static ShaderSocketType convert_osl_socket_type(OSL::OSLQuery& query,
}
#endif /* WITH_OSL */
static void set_default_value(ShaderInput *input, BL::NodeSocket b_sock, BL::BlendData b_data, BL::ID b_id)
static void set_default_value(ShaderInput *input,
BL::NodeSocket& b_sock,
BL::BlendData& b_data,
BL::ID& b_id)
{
/* copy values for non linked inputs */
switch(input->type) {
@ -166,7 +171,7 @@ static void set_default_value(ShaderInput *input, BL::NodeSocket b_sock, BL::Ble
}
}
static void get_tex_mapping(TextureMapping *mapping, BL::TexMapping b_mapping)
static void get_tex_mapping(TextureMapping *mapping, BL::TexMapping& b_mapping)
{
if(!b_mapping)
return;
@ -181,7 +186,8 @@ static void get_tex_mapping(TextureMapping *mapping, BL::TexMapping b_mapping)
mapping->z_mapping = (TextureMapping::Mapping)b_mapping.mapping_z();
}
static void get_tex_mapping(TextureMapping *mapping, BL::ShaderNodeMapping b_mapping)
static void get_tex_mapping(TextureMapping *mapping,
BL::ShaderNodeMapping& b_mapping)
{
if(!b_mapping)
return;
@ -199,7 +205,7 @@ static void get_tex_mapping(TextureMapping *mapping, BL::ShaderNodeMapping b_map
mapping->max = get_float3(b_mapping.max());
}
static bool is_output_node(BL::Node b_node)
static bool is_output_node(BL::Node& b_node)
{
return (b_node.is_a(&RNA_ShaderNodeOutputMaterial)
|| b_node.is_a(&RNA_ShaderNodeOutputWorld)
@ -207,13 +213,13 @@ static bool is_output_node(BL::Node b_node)
}
static ShaderNode *add_node(Scene *scene,
BL::RenderEngine b_engine,
BL::BlendData b_data,
BL::Scene b_scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Scene& b_scene,
const bool background,
ShaderGraph *graph,
BL::ShaderNodeTree b_ntree,
BL::ShaderNode b_node)
BL::ShaderNodeTree& b_ntree,
BL::ShaderNode& b_node)
{
ShaderNode *node = NULL;
@ -243,8 +249,9 @@ static ShaderNode *add_node(Scene *scene,
else if(b_node.is_a(&RNA_ShaderNodeValToRGB)) {
RGBRampNode *ramp = new RGBRampNode();
BL::ShaderNodeValToRGB b_ramp_node(b_node);
colorramp_to_array(b_ramp_node.color_ramp(), ramp->ramp, RAMP_TABLE_SIZE);
ramp->interpolate = b_ramp_node.color_ramp().interpolation() != BL::ColorRamp::interpolation_CONSTANT;
BL::ColorRamp b_color_ramp(b_ramp_node.color_ramp());
colorramp_to_array(b_color_ramp, ramp->ramp, RAMP_TABLE_SIZE);
ramp->interpolate = b_color_ramp.interpolation() != BL::ColorRamp::interpolation_CONSTANT;
node = ramp;
}
else if(b_node.is_a(&RNA_ShaderNodeRGB)) {
@ -608,6 +615,7 @@ static ShaderNode *add_node(Scene *scene,
else if(b_node.is_a(&RNA_ShaderNodeTexImage)) {
BL::ShaderNodeTexImage b_image_node(b_node);
BL::Image b_image(b_image_node.image());
BL::ImageUser b_image_user(b_image_node.image_user());
ImageTextureNode *image = new ImageTextureNode();
if(b_image) {
/* builtin images will use callback-based reading because
@ -626,12 +634,15 @@ static ShaderNode *add_node(Scene *scene,
* builtin names for packed images and movies
*/
int scene_frame = b_scene.frame_current();
int image_frame = image_user_frame_number(b_image_node.image_user(), scene_frame);
int image_frame = image_user_frame_number(b_image_user,
scene_frame);
image->filename = b_image.name() + "@" + string_printf("%d", image_frame);
image->builtin_data = b_image.ptr.data;
}
else {
image->filename = image_user_file_path(b_image_node.image_user(), b_image, b_scene.frame_current());
image->filename = image_user_file_path(b_image_user,
b_image,
b_scene.frame_current());
image->builtin_data = NULL;
}
@ -652,12 +663,14 @@ static ShaderNode *add_node(Scene *scene,
image->interpolation = (InterpolationType)b_image_node.interpolation();
image->extension = (ExtensionType)b_image_node.extension();
image->projection_blend = b_image_node.projection_blend();
get_tex_mapping(&image->tex_mapping, b_image_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_image_node.texture_mapping());
get_tex_mapping(&image->tex_mapping, b_texture_mapping);
node = image;
}
else if(b_node.is_a(&RNA_ShaderNodeTexEnvironment)) {
BL::ShaderNodeTexEnvironment b_env_node(b_node);
BL::Image b_image(b_env_node.image());
BL::ImageUser b_image_user(b_env_node.image_user());
EnvironmentTextureNode *env = new EnvironmentTextureNode();
if(b_image) {
bool is_builtin = b_image.packed_file() ||
@ -667,12 +680,15 @@ static ShaderNode *add_node(Scene *scene,
if(is_builtin) {
int scene_frame = b_scene.frame_current();
int image_frame = image_user_frame_number(b_env_node.image_user(), scene_frame);
int image_frame = image_user_frame_number(b_image_user,
scene_frame);
env->filename = b_image.name() + "@" + string_printf("%d", image_frame);
env->builtin_data = b_image.ptr.data;
}
else {
env->filename = image_user_file_path(b_env_node.image_user(), b_image, b_scene.frame_current());
env->filename = image_user_file_path(b_image_user,
b_image,
b_scene.frame_current());
env->animated = b_env_node.image_user().use_auto_refresh();
env->builtin_data = NULL;
}
@ -690,28 +706,32 @@ static ShaderNode *add_node(Scene *scene,
env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()];
env->interpolation = (InterpolationType)b_env_node.interpolation();
env->projection = EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()];
get_tex_mapping(&env->tex_mapping, b_env_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_env_node.texture_mapping());
get_tex_mapping(&env->tex_mapping, b_texture_mapping);
node = env;
}
else if(b_node.is_a(&RNA_ShaderNodeTexGradient)) {
BL::ShaderNodeTexGradient b_gradient_node(b_node);
GradientTextureNode *gradient = new GradientTextureNode();
gradient->type = GradientTextureNode::type_enum[(int)b_gradient_node.gradient_type()];
get_tex_mapping(&gradient->tex_mapping, b_gradient_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_gradient_node.texture_mapping());
get_tex_mapping(&gradient->tex_mapping, b_texture_mapping);
node = gradient;
}
else if(b_node.is_a(&RNA_ShaderNodeTexVoronoi)) {
BL::ShaderNodeTexVoronoi b_voronoi_node(b_node);
VoronoiTextureNode *voronoi = new VoronoiTextureNode();
voronoi->coloring = VoronoiTextureNode::coloring_enum[(int)b_voronoi_node.coloring()];
get_tex_mapping(&voronoi->tex_mapping, b_voronoi_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_voronoi_node.texture_mapping());
get_tex_mapping(&voronoi->tex_mapping, b_texture_mapping);
node = voronoi;
}
else if(b_node.is_a(&RNA_ShaderNodeTexMagic)) {
BL::ShaderNodeTexMagic b_magic_node(b_node);
MagicTextureNode *magic = new MagicTextureNode();
magic->depth = b_magic_node.turbulence_depth();
get_tex_mapping(&magic->tex_mapping, b_magic_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_magic_node.texture_mapping());
get_tex_mapping(&magic->tex_mapping, b_texture_mapping);
node = magic;
}
else if(b_node.is_a(&RNA_ShaderNodeTexWave)) {
@ -719,13 +739,15 @@ static ShaderNode *add_node(Scene *scene,
WaveTextureNode *wave = new WaveTextureNode();
wave->type = WaveTextureNode::type_enum[(int)b_wave_node.wave_type()];
wave->profile = WaveTextureNode::profile_enum[(int)b_wave_node.wave_profile()];
get_tex_mapping(&wave->tex_mapping, b_wave_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_wave_node.texture_mapping());
get_tex_mapping(&wave->tex_mapping, b_texture_mapping);
node = wave;
}
else if(b_node.is_a(&RNA_ShaderNodeTexChecker)) {
BL::ShaderNodeTexChecker b_checker_node(b_node);
CheckerTextureNode *checker = new CheckerTextureNode();
get_tex_mapping(&checker->tex_mapping, b_checker_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_checker_node.texture_mapping());
get_tex_mapping(&checker->tex_mapping, b_texture_mapping);
node = checker;
}
else if(b_node.is_a(&RNA_ShaderNodeTexBrick)) {
@ -735,20 +757,23 @@ static ShaderNode *add_node(Scene *scene,
brick->offset_frequency = b_brick_node.offset_frequency();
brick->squash = b_brick_node.squash();
brick->squash_frequency = b_brick_node.squash_frequency();
get_tex_mapping(&brick->tex_mapping, b_brick_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_brick_node.texture_mapping());
get_tex_mapping(&brick->tex_mapping, b_texture_mapping);
node = brick;
}
else if(b_node.is_a(&RNA_ShaderNodeTexNoise)) {
BL::ShaderNodeTexNoise b_noise_node(b_node);
NoiseTextureNode *noise = new NoiseTextureNode();
get_tex_mapping(&noise->tex_mapping, b_noise_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_noise_node.texture_mapping());
get_tex_mapping(&noise->tex_mapping, b_texture_mapping);
node = noise;
}
else if(b_node.is_a(&RNA_ShaderNodeTexMusgrave)) {
BL::ShaderNodeTexMusgrave b_musgrave_node(b_node);
MusgraveTextureNode *musgrave = new MusgraveTextureNode();
musgrave->type = MusgraveTextureNode::type_enum[(int)b_musgrave_node.musgrave_type()];
get_tex_mapping(&musgrave->tex_mapping, b_musgrave_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_musgrave_node.texture_mapping());
get_tex_mapping(&musgrave->tex_mapping, b_texture_mapping);
node = musgrave;
}
else if(b_node.is_a(&RNA_ShaderNodeTexCoord)) {
@ -768,7 +793,8 @@ static ShaderNode *add_node(Scene *scene,
sky->sun_direction = normalize(get_float3(b_sky_node.sun_direction()));
sky->turbidity = b_sky_node.turbidity();
sky->ground_albedo = b_sky_node.ground_albedo();
get_tex_mapping(&sky->tex_mapping, b_sky_node.texture_mapping());
BL::TexMapping b_texture_mapping(b_sky_node.texture_mapping());
get_tex_mapping(&sky->tex_mapping, b_texture_mapping);
node = sky;
}
else if(b_node.is_a(&RNA_ShaderNodeNormalMap)) {
@ -850,7 +876,9 @@ static bool node_use_modified_socket_name(ShaderNode *node)
return true;
}
static ShaderInput *node_find_input_by_name(ShaderNode *node, BL::Node b_node, BL::NodeSocket b_socket)
static ShaderInput *node_find_input_by_name(ShaderNode *node,
BL::Node& b_node,
BL::NodeSocket& b_socket)
{
string name = b_socket.name();
@ -881,7 +909,9 @@ static ShaderInput *node_find_input_by_name(ShaderNode *node, BL::Node b_node, B
return node->input(name.c_str());
}
static ShaderOutput *node_find_output_by_name(ShaderNode *node, BL::Node b_node, BL::NodeSocket b_socket)
static ShaderOutput *node_find_output_by_name(ShaderNode *node,
BL::Node& b_node,
BL::NodeSocket& b_socket)
{
string name = b_socket.name();
@ -913,12 +943,12 @@ static ShaderOutput *node_find_output_by_name(ShaderNode *node, BL::Node b_node,
}
static void add_nodes(Scene *scene,
BL::RenderEngine b_engine,
BL::BlendData b_data,
BL::Scene b_scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Scene& b_scene,
const bool background,
ShaderGraph *graph,
BL::ShaderNodeTree b_ntree,
BL::ShaderNodeTree& b_ntree,
const ProxyMap &proxy_input_map,
const ProxyMap &proxy_output_map)
{
@ -955,7 +985,8 @@ static void add_nodes(Scene *scene,
/* replace muted node with internal links */
BL::Node::internal_links_iterator b_link;
for(b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); ++b_link) {
ProxyNode *proxy = new ProxyNode(convert_socket_type(b_link->to_socket()));
BL::NodeSocket to_socket(b_link->to_socket());
ProxyNode *proxy = new ProxyNode(convert_socket_type(to_socket));
input_map[b_link->from_socket().ptr.data] = proxy->inputs[0];
output_map[b_link->to_socket().ptr.data] = proxy->outputs[0];
@ -1046,6 +1077,7 @@ static void add_nodes(Scene *scene,
}
}
else {
BL::ShaderNode b_shader_node(*b_node);
node = add_node(scene,
b_engine,
b_data,
@ -1053,7 +1085,7 @@ static void add_nodes(Scene *scene,
background,
graph,
b_ntree,
BL::ShaderNode(*b_node));
b_shader_node);
}
if(node) {
@ -1110,12 +1142,12 @@ static void add_nodes(Scene *scene,
}
static void add_nodes(Scene *scene,
BL::RenderEngine b_engine,
BL::BlendData b_data,
BL::Scene b_scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Scene& b_scene,
const bool background,
ShaderGraph *graph,
BL::ShaderNodeTree b_ntree)
BL::ShaderNodeTree& b_ntree)
{
static const ProxyMap empty_proxy_map;
add_nodes(scene,

View File

@ -42,22 +42,29 @@ CCL_NAMESPACE_BEGIN
/* Constructor */
BlenderSync::BlenderSync(BL::RenderEngine b_engine_, BL::BlendData b_data_, BL::Scene b_scene_, Scene *scene_, bool preview_, Progress &progress_, bool is_cpu_)
: b_engine(b_engine_),
b_data(b_data_), b_scene(b_scene_),
shader_map(&scene_->shaders),
object_map(&scene_->objects),
mesh_map(&scene_->meshes),
light_map(&scene_->lights),
particle_system_map(&scene_->particle_systems),
BlenderSync::BlenderSync(BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Scene& b_scene,
Scene *scene,
bool preview,
Progress &progress,
bool is_cpu)
: b_engine(b_engine),
b_data(b_data),
b_scene(b_scene),
shader_map(&scene->shaders),
object_map(&scene->objects),
mesh_map(&scene->meshes),
light_map(&scene->lights),
particle_system_map(&scene->particle_systems),
world_map(NULL),
world_recalc(false),
scene(scene),
preview(preview),
experimental(false),
progress(progress_)
is_cpu(is_cpu),
progress(progress)
{
scene = scene_;
preview = preview_;
is_cpu = is_cpu_;
}
BlenderSync::~BlenderSync()
@ -145,9 +152,9 @@ bool BlenderSync::sync_recalc()
return recalc;
}
void BlenderSync::sync_data(BL::RenderSettings b_render,
BL::SpaceView3D b_v3d,
BL::Object b_override,
void BlenderSync::sync_data(BL::RenderSettings& b_render,
BL::SpaceView3D& b_v3d,
BL::Object& b_override,
int width, int height,
void **python_thread_state,
const char *layer)
@ -308,7 +315,7 @@ void BlenderSync::sync_film()
/* Render Layer */
void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer)
void BlenderSync::sync_render_layers(BL::SpaceView3D& b_v3d, const char *layer)
{
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
string layername;
@ -416,7 +423,9 @@ void BlenderSync::sync_images()
/* Scene Parameters */
SceneParams BlenderSync::get_scene_params(BL::Scene b_scene, bool background, bool is_cpu)
SceneParams BlenderSync::get_scene_params(BL::Scene& b_scene,
bool background,
bool is_cpu)
{
BL::RenderSettings r = b_scene.render();
SceneParams params;
@ -455,15 +464,15 @@ SceneParams BlenderSync::get_scene_params(BL::Scene b_scene, bool background, bo
/* Session Parameters */
bool BlenderSync::get_session_pause(BL::Scene b_scene, bool background)
bool BlenderSync::get_session_pause(BL::Scene& b_scene, bool background)
{
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
return (background)? false: get_boolean(cscene, "preview_pause");
}
SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine,
BL::UserPreferences b_userpref,
BL::Scene b_scene,
SessionParams BlenderSync::get_session_params(BL::RenderEngine& b_engine,
BL::UserPreferences& b_userpref,
BL::Scene& b_scene,
bool background)
{
SessionParams params;

View File

@ -48,41 +48,57 @@ class ShaderNode;
class BlenderSync {
public:
BlenderSync(BL::RenderEngine b_engine_, BL::BlendData b_data, BL::Scene b_scene, Scene *scene_, bool preview_, Progress &progress_, bool is_cpu_);
BlenderSync(BL::RenderEngine& b_engine,
BL::BlendData& b_data,
BL::Scene& b_scene,
Scene *scene,
bool preview,
Progress &progress,
bool is_cpu);
~BlenderSync();
/* sync */
bool sync_recalc();
void sync_data(BL::RenderSettings b_render,
BL::SpaceView3D b_v3d,
BL::Object b_override,
void sync_data(BL::RenderSettings& b_render,
BL::SpaceView3D& b_v3d,
BL::Object& b_override,
int width, int height,
void **python_thread_state,
const char *layer = 0);
void sync_render_layers(BL::SpaceView3D b_v3d, const char *layer);
void sync_render_layers(BL::SpaceView3D& b_v3d, const char *layer);
void sync_integrator();
void sync_camera(BL::RenderSettings b_render, BL::Object b_override, int width, int height);
void sync_view(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height);
int get_layer_samples() { return render_layer.samples; }
int get_layer_bound_samples() { return render_layer.bound_samples; }
void sync_camera(BL::RenderSettings& b_render,
BL::Object& b_override,
int width, int height);
void sync_view(BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
int width, int height);
inline int get_layer_samples() { return render_layer.samples; }
inline int get_layer_bound_samples() { return render_layer.bound_samples; }
/* get parameters */
static SceneParams get_scene_params(BL::Scene b_scene, bool background, bool is_cpu);
static SessionParams get_session_params(BL::RenderEngine b_engine,
BL::UserPreferences b_userpref,
BL::Scene b_scene,
static SceneParams get_scene_params(BL::Scene& b_scene,
bool background,
bool is_cpu);
static SessionParams get_session_params(BL::RenderEngine& b_engine,
BL::UserPreferences& b_userpref,
BL::Scene& b_scene,
bool background);
static bool get_session_pause(BL::Scene b_scene, bool background);
static BufferParams get_buffer_params(BL::RenderSettings b_render, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, Camera *cam, int width, int height);
static bool get_session_pause(BL::Scene& b_scene, bool background);
static BufferParams get_buffer_params(BL::RenderSettings& b_render,
BL::SpaceView3D& b_v3d,
BL::RegionView3D& b_rv3d,
Camera *cam,
int width, int height);
private:
/* sync */
void sync_lamps(bool update_all);
void sync_materials(bool update_all);
void sync_objects(BL::SpaceView3D b_v3d, float motion_time = 0.0f);
void sync_motion(BL::RenderSettings b_render,
BL::SpaceView3D b_v3d,
BL::Object b_override,
void sync_objects(BL::SpaceView3D& b_v3d, float motion_time = 0.0f);
void sync_motion(BL::RenderSettings& b_render,
BL::SpaceView3D& b_v3d,
BL::Object& b_override,
int width, int height,
void **python_thread_state);
void sync_film();
@ -91,12 +107,16 @@ private:
void sync_shaders();
void sync_curve_settings();
void sync_nodes(Shader *shader, BL::ShaderNodeTree b_ntree);
Mesh *sync_mesh(BL::Object b_ob, bool object_updated, bool hide_tris);
void sync_curves(Mesh *mesh, BL::Mesh b_mesh, BL::Object b_ob, bool motion, int time_index = 0);
Object *sync_object(BL::Object b_parent,
void sync_nodes(Shader *shader, BL::ShaderNodeTree& b_ntree);
Mesh *sync_mesh(BL::Object& b_ob, bool object_updated, bool hide_tris);
void sync_curves(Mesh *mesh,
BL::Mesh& b_mesh,
BL::Object& b_ob,
bool motion,
int time_index = 0);
Object *sync_object(BL::Object& b_parent,
int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
BL::DupliObject b_dupli_ob,
BL::DupliObject& b_dupli_ob,
Transform& tfm,
uint layer_flag,
float motion_time,
@ -104,25 +124,31 @@ private:
bool use_camera_cull,
float camera_cull_margin,
bool *use_portal);
void sync_light(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::Object b_ob, Transform& tfm, bool *use_portal);
void sync_light(BL::Object& b_parent,
int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
BL::Object& b_ob,
Transform& tfm,
bool *use_portal);
void sync_background_light(bool use_portal);
void sync_mesh_motion(BL::Object b_ob, Object *object, float motion_time);
void sync_camera_motion(BL::RenderSettings b_render,
BL::Object b_ob,
void sync_mesh_motion(BL::Object& b_ob, Object *object, float motion_time);
void sync_camera_motion(BL::RenderSettings& b_render,
BL::Object& b_ob,
int width, int height,
float motion_time);
/* particles */
bool sync_dupli_particle(BL::Object b_ob, BL::DupliObject b_dup, Object *object);
bool sync_dupli_particle(BL::Object& b_ob,
BL::DupliObject& b_dup,
Object *object);
/* Images. */
void sync_images();
/* util */
void find_shader(BL::ID id, vector<uint>& 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);
void find_shader(BL::ID& id, vector<uint>& 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);
/* variables */
BL::RenderEngine b_engine;

View File

@ -34,8 +34,8 @@ void density_texture_space_invert(float3& loc,
} /* namespace */
void point_density_texture_space(BL::Scene b_scene,
BL::ShaderNodeTexPointDensity b_point_density_node,
void point_density_texture_space(BL::Scene& b_scene,
BL::ShaderNodeTexPointDensity& b_point_density_node,
int settings,
float3& loc,
float3& size)

View File

@ -22,8 +22,8 @@
CCL_NAMESPACE_BEGIN
void point_density_texture_space(BL::Scene b_scene,
BL::ShaderNodeTexPointDensity b_point_density_node,
void point_density_texture_space(BL::Scene& b_scene,
BL::ShaderNodeTexPointDensity& b_point_density_node,
const int settings,
float3& loc,
float3& size);

View File

@ -40,7 +40,12 @@ CCL_NAMESPACE_BEGIN
void python_thread_state_save(void **python_thread_state);
void python_thread_state_restore(void **python_thread_state);
static inline BL::Mesh object_to_mesh(BL::BlendData data, BL::Object object, BL::Scene scene, bool apply_modifiers, bool render, bool calc_undeformed)
static inline BL::Mesh object_to_mesh(BL::BlendData& data,
BL::Object& object,
BL::Scene& scene,
bool apply_modifiers,
bool render,
bool calc_undeformed)
{
BL::Mesh me = data.meshes.new_from_object(scene, object, apply_modifiers, (render)? 2: 1, false, calc_undeformed);
if((bool)me) {
@ -52,7 +57,9 @@ static inline BL::Mesh object_to_mesh(BL::BlendData data, BL::Object object, BL:
return me;
}
static inline void colorramp_to_array(BL::ColorRamp ramp, float4 *data, int size)
static inline void colorramp_to_array(BL::ColorRamp& ramp,
float4 *data,
int size)
{
for(int i = 0; i < size; i++) {
float color[4];
@ -85,7 +92,9 @@ static inline void curvemapping_minmax(/*const*/ BL::CurveMapping& cumap,
}
}
static inline void curvemapping_to_array(BL::CurveMapping cumap, float *data, int size)
static inline void curvemapping_to_array(BL::CurveMapping& cumap,
float *data,
int size)
{
cumap.update();
BL::CurveMap curve = cumap.curves[0];
@ -95,7 +104,7 @@ static inline void curvemapping_to_array(BL::CurveMapping cumap, float *data, in
}
}
static inline void curvemapping_color_to_array(BL::CurveMapping cumap,
static inline void curvemapping_color_to_array(BL::CurveMapping& cumap,
float4 *data,
int size,
bool rgb_curve)
@ -145,27 +154,33 @@ static inline void curvemapping_color_to_array(BL::CurveMapping cumap,
}
}
static inline bool BKE_object_is_modified(BL::Object self, BL::Scene scene, bool preview)
static inline bool BKE_object_is_modified(BL::Object& self,
BL::Scene& scene,
bool preview)
{
return self.is_modified(scene, (preview)? (1<<0): (1<<1))? true: false;
}
static inline bool BKE_object_is_deform_modified(BL::Object self, BL::Scene scene, bool preview)
static inline bool BKE_object_is_deform_modified(BL::Object& self,
BL::Scene& scene,
bool preview)
{
return self.is_deform_modified(scene, (preview)? (1<<0): (1<<1))? true: false;
}
static inline int render_resolution_x(BL::RenderSettings b_render)
static inline int render_resolution_x(BL::RenderSettings& b_render)
{
return b_render.resolution_x()*b_render.resolution_percentage()/100;
}
static inline int render_resolution_y(BL::RenderSettings b_render)
static inline int render_resolution_y(BL::RenderSettings& b_render)
{
return b_render.resolution_y()*b_render.resolution_percentage()/100;
}
static inline string image_user_file_path(BL::ImageUser iuser, BL::Image ima, int cfra)
static inline string image_user_file_path(BL::ImageUser& iuser,
BL::Image& ima,
int cfra)
{
char filepath[1024];
BKE_image_user_frame_calc(iuser.ptr.data, cfra, 0);
@ -173,25 +188,27 @@ static inline string image_user_file_path(BL::ImageUser iuser, BL::Image ima, in
return string(filepath);
}
static inline int image_user_frame_number(BL::ImageUser iuser, int cfra)
static inline int image_user_frame_number(BL::ImageUser& iuser, int cfra)
{
BKE_image_user_frame_calc(iuser.ptr.data, cfra, 0);
return iuser.frame_current();
}
static inline unsigned char *image_get_pixels_for_frame(BL::Image image, int frame)
static inline unsigned char *image_get_pixels_for_frame(BL::Image& image,
int frame)
{
return BKE_image_get_pixels_for_frame(image.ptr.data, frame);
}
static inline float *image_get_float_pixels_for_frame(BL::Image image, int frame)
static inline float *image_get_float_pixels_for_frame(BL::Image& image,
int frame)
{
return BKE_image_get_float_pixels_for_frame(image.ptr.data, frame);
}
/* Utilities */
static inline Transform get_transform(BL::Array<float, 16> array)
static inline Transform get_transform(const BL::Array<float, 16>& array)
{
Transform tfm;
@ -203,42 +220,42 @@ static inline Transform get_transform(BL::Array<float, 16> array)
return tfm;
}
static inline float2 get_float2(BL::Array<float, 2> array)
static inline float2 get_float2(const BL::Array<float, 2>& array)
{
return make_float2(array[0], array[1]);
}
static inline float3 get_float3(BL::Array<float, 2> array)
static inline float3 get_float3(const BL::Array<float, 2>& array)
{
return make_float3(array[0], array[1], 0.0f);
}
static inline float3 get_float3(BL::Array<float, 3> array)
static inline float3 get_float3(const BL::Array<float, 3>& array)
{
return make_float3(array[0], array[1], array[2]);
}
static inline float3 get_float3(BL::Array<float, 4> array)
static inline float3 get_float3(const BL::Array<float, 4>& array)
{
return make_float3(array[0], array[1], array[2]);
}
static inline float4 get_float4(BL::Array<float, 4> array)
static inline float4 get_float4(const BL::Array<float, 4>& array)
{
return make_float4(array[0], array[1], array[2], array[3]);
}
static inline int3 get_int3(BL::Array<int, 3> array)
static inline int3 get_int3(const BL::Array<int, 3>& array)
{
return make_int3(array[0], array[1], array[2]);
}
static inline int4 get_int4(BL::Array<int, 4> array)
static inline int4 get_int4(const BL::Array<int, 4>& array)
{
return make_int4(array[0], array[1], array[2], array[3]);
}
static inline uint get_layer(BL::Array<int, 20> array)
static inline uint get_layer(const BL::Array<int, 20>& array)
{
uint layer = 0;
@ -249,8 +266,8 @@ static inline uint get_layer(BL::Array<int, 20> array)
return layer;
}
static inline uint get_layer(BL::Array<int, 20> array,
BL::Array<int, 8> local_array,
static inline uint get_layer(const BL::Array<int, 20>& array,
const BL::Array<int, 8>& local_array,
bool use_local,
bool is_light = false,
uint scene_layers = (1 << 20) - 1)
@ -384,13 +401,19 @@ static inline void set_string(PointerRNA& ptr, const char *name, const string &v
/* Relative Paths */
static inline string blender_absolute_path(BL::BlendData b_data, BL::ID b_id, const string& path)
static inline string blender_absolute_path(BL::BlendData& b_data,
BL::ID& b_id,
const string& path)
{
if(path.size() >= 2 && path[0] == '/' && path[1] == '/') {
string dirname;
if(b_id.library())
dirname = blender_absolute_path(b_data, b_id.library(), b_id.library().filepath());
if(b_id.library()) {
BL::ID b_library_id(b_id.library());
dirname = blender_absolute_path(b_data,
b_library_id,
b_id.library().filepath());
}
else
dirname = b_data.filepath();
@ -402,7 +425,9 @@ static inline string blender_absolute_path(BL::BlendData b_data, BL::ID b_id, co
/* Texture Space */
static inline void mesh_texture_space(BL::Mesh b_mesh, float3& loc, float3& size)
static inline void mesh_texture_space(BL::Mesh& b_mesh,
float3& loc,
float3& size)
{
loc = get_float3(b_mesh.texspace_location());
size = get_float3(b_mesh.texspace_size());
@ -415,7 +440,7 @@ static inline void mesh_texture_space(BL::Mesh b_mesh, float3& loc, float3& size
}
/* object used for motion blur */
static inline bool object_use_motion(BL::Object b_parent, BL::Object b_ob)
static inline bool object_use_motion(BL::Object& b_parent, BL::Object& b_ob)
{
PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles");
bool use_motion = get_boolean(cobject, "use_motion_blur");
@ -433,7 +458,7 @@ static inline bool object_use_motion(BL::Object b_parent, BL::Object b_ob)
}
/* object motion steps */
static inline uint object_motion_steps(BL::Object b_ob)
static inline uint object_motion_steps(BL::Object& b_ob)
{
PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles");
uint steps = get_int(cobject, "motion_steps");
@ -445,7 +470,8 @@ static inline uint object_motion_steps(BL::Object b_ob)
}
/* object uses deformation motion blur */
static inline bool object_use_deform_motion(BL::Object b_parent, BL::Object b_ob)
static inline bool object_use_deform_motion(BL::Object& b_parent,
BL::Object& b_ob)
{
PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles");
bool use_deform_motion = get_boolean(cobject, "use_deform_motion");
@ -462,7 +488,7 @@ static inline bool object_use_deform_motion(BL::Object b_parent, BL::Object b_ob
return use_deform_motion;
}
static inline BL::SmokeDomainSettings object_smoke_domain_find(BL::Object b_ob)
static inline BL::SmokeDomainSettings object_smoke_domain_find(BL::Object& b_ob)
{
BL::Object::modifiers_iterator b_mod;
@ -491,7 +517,7 @@ public:
scene_data = scene_data_;
}
T *find(BL::ID id)
T *find(const BL::ID& id)
{
return find(id.ptr.id.data);
}
@ -506,7 +532,7 @@ public:
return NULL;
}
void set_recalc(BL::ID id)
void set_recalc(const BL::ID& id)
{
b_recalc.insert(id.ptr.data);
}
@ -521,12 +547,12 @@ public:
used_set.clear();
}
bool sync(T **r_data, BL::ID id)
bool sync(T **r_data, const BL::ID& id)
{
return sync(r_data, id, id, id.ptr.id.data);
}
bool sync(T **r_data, BL::ID id, BL::ID parent, const K& key)
bool sync(T **r_data, const BL::ID& id, const BL::ID& parent, const K& key)
{
T *data = find(key);
bool recalc;

View File

@ -3692,6 +3692,7 @@ static const char *cpp_classes = ""
"return *this; }\n"
"\n"
" operator T*() { return data; }\n"
" operator const T*() const { return data; }\n"
"};\n"
"\n"
"template<typename T>\n"