[Bf-blender-cvs] [286a4ad] viewport_bvh_select: Avoid allocating bounding boxes
Julian Eisel
noreply at git.blender.org
Sun Aug 28 04:22:21 CEST 2016
Commit: 286a4ad6f9f773d2862530227b61a8aacfb253b9
Author: Julian Eisel
Date: Sun Aug 28 04:21:48 2016 +0200
Branches: viewport_bvh_select
https://developer.blender.org/rB286a4ad6f9f773d2862530227b61a8aacfb253b9
Avoid allocating bounding boxes
===================================================================
M source/blender/blenkernel/BKE_camera.h
M source/blender/blenkernel/BKE_empty.h
M source/blender/blenkernel/BKE_lamp.h
M source/blender/blenkernel/BKE_object.h
M source/blender/blenkernel/BKE_speaker.h
M source/blender/blenkernel/intern/camera.c
M source/blender/blenkernel/intern/empty.c
M source/blender/blenkernel/intern/lamp.c
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/speaker.c
M source/blender/editors/space_view3d/view3d_bvh.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_camera.h b/source/blender/blenkernel/BKE_camera.h
index f509f24..fc4287a 100644
--- a/source/blender/blenkernel/BKE_camera.h
+++ b/source/blender/blenkernel/BKE_camera.h
@@ -38,6 +38,7 @@ extern "C" {
#include "DNA_vec_types.h"
+struct BoundBox;
struct Camera;
struct Main;
struct Object;
@@ -64,7 +65,7 @@ void BKE_camera_object_mode(struct RenderData *rd, struct Object *ob);
int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey);
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y);
-struct BoundBox *BKE_camera_drawboundbox_get(const struct Scene *scene, const struct Object *ob);
+void BKE_camera_drawboundbox_get(const struct Scene *scene, const struct Object *ob, struct BoundBox *r_bb);
/* Camera Parameters:
*
diff --git a/source/blender/blenkernel/BKE_empty.h b/source/blender/blenkernel/BKE_empty.h
index cc814d0..fe362b6 100644
--- a/source/blender/blenkernel/BKE_empty.h
+++ b/source/blender/blenkernel/BKE_empty.h
@@ -26,13 +26,14 @@
* \brief General operations for empties (object type).
*/
+struct BoundBox;
struct Image;
struct ImBuf;
struct Object;
void BKE_empty_draw_type_set(struct Object *ob, const int value);
-struct BoundBox *BKE_empty_drawboundbox_get(const struct Object *ob);
+void BKE_empty_drawboundbox_get(const struct Object *ob, struct BoundBox *r_bb);
void BKE_empty_imbuf_get(
const struct Object *ob,
diff --git a/source/blender/blenkernel/BKE_lamp.h b/source/blender/blenkernel/BKE_lamp.h
index 58be8f4..00dcaca 100644
--- a/source/blender/blenkernel/BKE_lamp.h
+++ b/source/blender/blenkernel/BKE_lamp.h
@@ -49,7 +49,7 @@ struct Lamp *localize_lamp(struct Lamp *la) ATTR_WARN_UNUSED_RESULT;
void BKE_lamp_make_local(struct Main *bmain, struct Lamp *la, const bool lib_local);
void BKE_lamp_free(struct Lamp *la);
-struct BoundBox *BKE_lamp_drawboundbox_get(const struct Lamp *la);
+void BKE_lamp_drawboundbox_get(const struct Lamp *la, struct BoundBox *r_bb);
void lamp_drivers_update(struct Scene *scene, struct Lamp *la, float ctime);
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index fc4dfdb..1498fc8 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -147,9 +147,9 @@ struct BoundBox *BKE_boundbox_ensure_minimum_dimensions(
struct BoundBox *bb, struct BoundBox *bb_temp, const float epsilon);
struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
-struct BoundBox *BKE_object_drawboundbox_get(
+void BKE_object_drawboundbox_get(
const struct Scene *scene, const struct Object *ob,
- bool *r_needs_freeing);
+ struct BoundBox *r_bb);
void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
void BKE_object_dimensions_set(struct Object *ob, const float value[3]);
void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set);
diff --git a/source/blender/blenkernel/BKE_speaker.h b/source/blender/blenkernel/BKE_speaker.h
index c895fcd..e8acafe 100644
--- a/source/blender/blenkernel/BKE_speaker.h
+++ b/source/blender/blenkernel/BKE_speaker.h
@@ -28,6 +28,7 @@
* \brief General operations for speakers.
*/
+struct BoundBox;
struct Main;
struct Speaker;
@@ -37,6 +38,6 @@ struct Speaker *BKE_speaker_copy(struct Main *bmain, struct Speaker *spk);
void BKE_speaker_make_local(struct Main *bmain, struct Speaker *spk, const bool lib_local);
void BKE_speaker_free(struct Speaker *spk);
-struct BoundBox *BKE_speaker_drawboundbox_get(void);
+void BKE_speaker_drawboundbox_get(struct BoundBox *r_bb);
#endif
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 158d1df..65c0813 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -57,8 +57,6 @@
#include "GPU_compositing.h"
-#include "MEM_guardedalloc.h"
-
/****************************** Camera Datablock *****************************/
@@ -175,13 +173,10 @@ int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
/**
* Even though our virtual cameras are infinite small points with some attributes,
* sometimes we need the bounding box that matches what the user sees.
- *
- * \return Allocated BoundBox in local space (needs freeing).
*/
-BoundBox *BKE_camera_drawboundbox_get(const Scene *scene, const Object *ob)
+void BKE_camera_drawboundbox_get(const Scene *scene, const Object *ob, BoundBox *r_bb)
{
Camera *cam = ob->data;
- BoundBox *bb = MEM_callocN(sizeof(*bb), "Camera boundbox");
float viewframe[4][3];
float min[3], max[3];
@@ -189,7 +184,6 @@ BoundBox *BKE_camera_drawboundbox_get(const Scene *scene, const Object *ob)
float dummy_shift[2];
float dummy_drawsize;
float scale[3] = {1.0f, 1.0f, 1.0f};
-
BKE_camera_view_frame_ex(
scene, cam, cam->drawsize, false,
scale, dummy_asp, dummy_shift, &dummy_drawsize,
@@ -202,9 +196,7 @@ BoundBox *BKE_camera_drawboundbox_get(const Scene *scene, const Object *ob)
const float origin[3] = {0.0f};
minmax_v3v3_v3(min, max, origin);
- BKE_boundbox_init_from_minmax(bb, min, max);
-
- return bb;
+ BKE_boundbox_init_from_minmax(r_bb, min, max);
}
/******************************** Camera Params *******************************/
diff --git a/source/blender/blenkernel/intern/empty.c b/source/blender/blenkernel/intern/empty.c
index daaf808..b01fa46 100644
--- a/source/blender/blenkernel/intern/empty.c
+++ b/source/blender/blenkernel/intern/empty.c
@@ -58,7 +58,7 @@ void BKE_empty_draw_type_set(Object *ob, const int value)
}
}
-BoundBox *BKE_empty_drawboundbox_get(const Object *ob)
+void BKE_empty_drawboundbox_get(const Object *ob, BoundBox *r_bb)
{
const float size = ob->empty_drawsize;
float min[3] = {0.0f};
@@ -106,10 +106,7 @@ BoundBox *BKE_empty_drawboundbox_get(const Object *ob)
break;
}
- BoundBox *bb = MEM_callocN(sizeof(*bb), "Empty Boundbox");
- BKE_boundbox_init_from_minmax(bb, min, max);
-
- return bb;
+ BKE_boundbox_init_from_minmax(r_bb, min, max);
}
/**
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 33cd38b..1a40460 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -244,18 +244,14 @@ void lamp_drivers_update(Scene *scene, Lamp *la, float ctime)
* Get the visual bounding box of lamps, without things like direction indicator etc (we don't
* want this for selecting). Should match what #drawlamp draws (keep in sync!).
*/
-BoundBox *BKE_lamp_drawboundbox_get(const Lamp *la)
+void BKE_lamp_drawboundbox_get(const Lamp *la, BoundBox *r_bb)
{
- BoundBox *bb = MEM_callocN(sizeof(*bb), "Lamp boundbox");
-
const bool draw_outer = la->type != LA_HEMI &&
((la->mode & LA_SHAD_RAY) || ((la->mode & LA_SHAD_BUF) && (la->type == LA_SPOT)));
const float lamprad = (float)U.obcenter_dia * 1.5f + (draw_outer ? 3.0f : 0.0f);
const float min[3] = {-lamprad, -lamprad, -lamprad};
const float max[3] = {lamprad, lamprad, lamprad};
- BKE_boundbox_init_from_minmax(bb, min, max);
-
- return bb;
+ BKE_boundbox_init_from_minmax(r_bb, min, max);
}
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 70db0b6..541f004 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2314,37 +2314,34 @@ BoundBox *BKE_object_boundbox_get(Object *ob)
/**
* For some cases we need the visual bounding box of objects that don't
* have real geometry, that are just infinite small points in space.
- *
- * \param r_needs_freeing: The bounding box may have been allocated and needs to be freed manually.
- * \return The visual bounding box in local space.
*/
-BoundBox *BKE_object_drawboundbox_get(
+void BKE_object_drawboundbox_get(
const Scene *scene, const Object *ob,
- bool *r_needs_freeing)
+ BoundBox *r_bb)
{
BoundBox *bb = BKE_object_boundbox_get((Object *)ob);
- *r_needs_freeing = (bb == NULL);
if (!bb) {
switch (ob->type) {
case OB_CAMERA:
- bb = BKE_camera_drawboundbox_get(scene, ob);
+ BKE_camera_drawboundbox_get(scene, ob, r_bb);
break;
case OB_EMPTY:
- bb = BKE_empty_drawboundbox_get(ob);
+ BKE_empty_drawboundbox_get(ob, r_bb);
break;
case OB_LAMP:
- bb = BKE_lamp_drawboundbox_get(ob->data);
+ BKE_lamp_drawboundbox_get(ob->data, r_bb);
break;
case OB_SPEAKER:
- bb = BKE_speaker_drawboundbox_get();
+ BKE_speaker_drawboundbox_get(r_bb);
break;
default:
break;
}
}
-
- return bb;
+ else {
+ *r_bb = *bb;
+ }
}
/* used to temporally disable/enable boundbox */
diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c
index 9087474..072fd4c 100644
--- a/source/blender/blenkernel/intern/speaker.c
+++ b/source/blender/blenkernel/intern/speaker.c
@@ -40,8 +40,6 @@
#include "BKE_object.h"
#include "BKE_speaker.h"
-#include "MEM_guardedalloc.h"
-
void BKE_speaker_init(Speaker *spk)
{
@@ -96,7 +94,7 @@ void BKE_speaker_free(Speaker *spk)
BKE_animdata_free((ID *)spk, false);
}
-BoundBox *BKE_speaker_drawboundbox_get(void)
+void BKE_speaker_drawboundbox_get(BoundBox *r_bb)
{
const float maxrad = 0.5f;
const float zmin = -0.125f;
@@ -104,8 +102,5 @@ BoundBox *BKE_speaker_drawboundbox_get(void)
const float min[3] = {-maxrad, -maxrad, zmin};
const float max[3] = {maxrad, maxrad, zmax};
- BoundBox *bb = MEM_callocN(sizeof(*bb), "Speaker BoundBox");
- BKE_boundbox_init_from_minmax(bb, min, max);
-
- return bb;
+ BKE_boundbox_init_from_minmax(r_bb, min, max);
}
diff --git a/source/blender/editors/space_view3d/view3d_bvh.c b/source/blender/editors/space_view3d/view3d_bvh.c
index 813c083..f99ff3e 100644
--- a/source/blender/editors/space_view3d/view3d_bvh.c
+++ b/source/blender/editors/space_view3d/view3d_bvh.c
@@ -44,35 +44,26 @@
static void bvh_objects_insert(View3D *v3d, const RegionView3D *rv3d, const Scene *scene)
{
Object *ob;
+ BoundBox bb;
int i = 0;
for (Base *base = scene->base.first; b
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list