View3D: disable LOD when game engine is disabled or ifdef'd
authorCampbell Barton <ideasman42@gmail.com>
Wed, 9 Apr 2014 01:48:04 +0000 (11:48 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 9 Apr 2014 01:52:34 +0000 (11:52 +1000)
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object.c
source/blender/editors/object/object_lod.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/gpu/CMakeLists.txt
source/blender/gpu/SConscript
source/blender/gpu/intern/gpu_draw.c
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_object.c

index 4b4deea044da4eb5b436976246dda6cd485e3d7c..c0da816ca59214038ad451859c89e587674a5d96 100644 (file)
@@ -92,7 +92,7 @@ void *BKE_object_obdata_add_from_type(struct Main *bmain, int type);
 void BKE_object_lod_add(struct Object *ob);
 void BKE_object_lod_sort(struct Object *ob);
 bool BKE_object_lod_remove(struct Object *ob, int level);
-bool BKE_object_lod_update(struct Object *ob, float camera_position[3]);
+void BKE_object_lod_update(struct Object *ob, const float camera_position[3]);
 bool BKE_object_lod_is_usable(struct Object *ob, struct Scene *scene);
 struct Object *BKE_object_lod_meshob_get(struct Object *ob, struct Scene *scene);
 struct Object *BKE_object_lod_matob_get(struct Object *ob, struct Scene *scene);
index 23af5bdf7badaaecc176cf34a98f89a76a970e58..71b3e83f9de127e46cef79238904b14130532cc9 100644 (file)
@@ -1049,6 +1049,9 @@ Object *BKE_object_add(Main *bmain, Scene *scene, int type)
        return ob;
 }
 
+
+#ifdef WITH_GAMEENGINE
+
 void BKE_object_lod_add(Object *ob)
 {
        LodLevel *lod = MEM_callocN(sizeof(LodLevel), "LoD Level");
@@ -1110,21 +1113,19 @@ bool BKE_object_lod_remove(Object *ob, int level)
        return true;
 }
 
-static LodLevel *lod_level_select(Object *ob, const float cam_loc[3])
+static LodLevel *lod_level_select(Object *ob, const float camera_position[3])
 {
        LodLevel *current = ob->currentlod;
-       float ob_loc[3], delta[3];
-       float dist_sq;
+       float dist_sq, dist_sq_curr;
 
        if (!current) return NULL;
 
-       copy_v3_v3(ob_loc, ob->obmat[3]);
-       sub_v3_v3v3(delta, ob_loc, cam_loc);
-       dist_sq = len_squared_v3(delta);
+       dist_sq = len_squared_v3v3(ob->obmat[3], camera_position);
+       dist_sq_curr = current->distance * current->distance;
 
-       if (dist_sq < current->distance * current->distance) {
+       if (dist_sq < dist_sq_curr) {
                /* check for higher LoD */
-               while (current->prev && dist_sq < (current->distance * current->distance)) {
+               while (current->prev && dist_sq < dist_sq_curr) {
                        current = current->prev;
                }
        }
@@ -1144,17 +1145,14 @@ bool BKE_object_lod_is_usable(Object *ob, Scene *scene)
        return (ob->mode == OB_MODE_OBJECT || !active);
 }
 
-bool BKE_object_lod_update(Object *ob, float camera_position[3])
+void BKE_object_lod_update(Object *ob, const float camera_position[3])
 {
        LodLevel *cur_level = ob->currentlod;
        LodLevel *new_level = lod_level_select(ob, camera_position);
 
        if (new_level != cur_level) {
                ob->currentlod = new_level;
-               return true;
        }
-
-       return false;
 }
 
 static Object *lod_ob_get(Object *ob, Scene *scene, int flag)
@@ -1181,6 +1179,9 @@ struct Object *BKE_object_lod_matob_get(Object *ob, Scene *scene)
        return lod_ob_get(ob, scene, OB_LOD_USE_MAT);
 }
 
+#endif  /* WITH_GAMEENGINE */
+
+
 SoftBody *copy_softbody(SoftBody *sb, bool copy_caches)
 {
        SoftBody *sbn;
index fdce59b10fff2ba1c90649160369adc24316382f..d02b69ba5cf167316a57a61fd0b426d3f9c921b7 100644 (file)
 static int object_lod_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *ob = ED_object_context(C);
+
+#ifdef WITH_GAMEENGINE
        BKE_object_lod_add(ob);
+#else
+       (void)ob;
+#endif
+
        return OPERATOR_FINISHED;
 }
 
@@ -75,8 +81,13 @@ static int object_lod_remove_exec(bContext *C, wmOperator *op)
        Object *ob = ED_object_context(C);
        int index = RNA_int_get(op->ptr, "index");
 
+#ifdef WITH_GAMEENGINE
        if (!BKE_object_lod_remove(ob, index))
                return OPERATOR_CANCELLED;
+#else
+       (void)ob;
+       (void)index;
+#endif
 
        WM_event_add_notifier(C, NC_OBJECT | ND_LOD, CTX_wm_view3d(C));
        return OPERATOR_FINISHED;
index e7f94485664451072e01fe22d6368dea64efeaca..13e74ece6925a8ff68601acf699666b50e3f1587 100644 (file)
@@ -3406,7 +3406,11 @@ static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
 static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
                             const char dt, const unsigned char ob_wire_col[4], const short dflag)
 {
-       Object *ob = BKE_object_lod_meshob_get(base->object, scene);
+#ifdef WITH_GAMEENGINE
+       Object *ob = (rv3d->rflag & RV3D_IS_GAME_ENGINE) ? BKE_object_lod_meshob_get(base->object, scene) : base->object;
+#else
+       Object *ob = base->object;
+#endif
        Mesh *me = ob->data;
        Material *ma = give_current_material(ob, 1);
        const bool hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO) && !BKE_scene_use_new_shading_nodes(scene));
index 9b455748713d5f25180f3b705c85cf70950f61e2..2552be9b83b5c927f0e56f2b866442ae9060bf78 100644 (file)
@@ -1992,8 +1992,12 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
                copy_m4_m4(savedobmat, dob->ob->obmat);
                copy_m4_m4(dob->ob->obmat, dob->mat);
                savedlod = dob->ob->currentlod;
-               BKE_object_lod_update(dob->ob, rv3d->viewinv[3]);
-               
+
+#ifdef WITH_GAMEENGINE
+               if (rv3d->rflag & RV3D_IS_GAME_ENGINE) {
+                       BKE_object_lod_update(dob->ob, rv3d->viewinv[3]);
+               }
+#endif
 
                /* extra service: draw the duplicator in drawtype of parent, minimum taken
                 * to allow e.g. boundbox box objects in groups for LOD */
@@ -3208,6 +3212,8 @@ static void view3d_main_area_clear(Scene *scene, View3D *v3d, ARegion *ar)
        }
 }
 
+
+#ifdef WITH_GAMEENGINE
 static void update_lods(Scene *scene, float camera_pos[3])
 {
        Scene *sce_iter;
@@ -3219,6 +3225,8 @@ static void update_lods(Scene *scene, float camera_pos[3])
                BKE_object_lod_update(ob, camera_pos);
        }
 }
+#endif
+
 
 /* warning: this function has duplicate drawing in ED_view3d_draw_offscreen() */
 static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const char **grid_unit)
@@ -3242,8 +3250,15 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
        /* setup view matrices */
        view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL);
 
-       /* Make sure LoDs are up to date */
-       update_lods(scene, rv3d->viewinv[3]);
+       rv3d->rflag &= ~RV3D_IS_GAME_ENGINE;
+#ifdef WITH_GAMEENGINE
+       if (STREQ(scene->r.engine, "BLENDER_GAME")) {
+               rv3d->rflag |= RV3D_IS_GAME_ENGINE;
+
+               /* Make sure LoDs are up to date */
+               update_lods(scene, rv3d->viewinv[3]);
+       }
+#endif
 
        /* clear the background */
        view3d_main_area_clear(scene, v3d, ar);
index 93c80c68f24cb4a0fec3dd85d5f5efb984c2a970..739deffa51904577861569abadfd9dc7ec50476d 100644 (file)
@@ -69,6 +69,10 @@ data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vsm_store_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vsm_store_vert.glsl SRC)
 
+if(WITH_GAMEENGINE)
+       add_definitions(-DWITH_GAMEENGINE)
+endif()
+
 if(WITH_MOD_SMOKE)
        add_definitions(-DWITH_SMOKE)
 endif()
index c1c3fa92cb1cef6ac9f0138cdcc3abc555d75290..e9320f08eff10516a6d51bd42fbf39b7ffc6a674 100644 (file)
@@ -49,6 +49,8 @@ incs = [
     env['BF_OPENGL_INC'],
     ]
 
+if env['WITH_BF_GAMEENGINE']:
+    defs.append('WITH_GAMEENGINE')
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'):
     incs.append(env['BF_PTHREADS_INC'])
 
index 99f98f713ce98c12772335400f6474b978cf9261..c22c4fbcdf45a0121039f826ccfc10f91b65775e 100644 (file)
@@ -1403,8 +1403,12 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
        const bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene);
        const bool use_matcap = (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) != 0;  /* assumes v3d->defmaterial->preview is set */
 
-       ob = BKE_object_lod_matob_get(ob, scene);
-       
+#ifdef WITH_GAMEENGINE
+       if (rv3d->rflag & RV3D_IS_GAME_ENGINE) {
+               ob = BKE_object_lod_matob_get(ob, scene);
+       }
+#endif
+
        /* initialize state */
        memset(&GMS, 0, sizeof(GMS));
        GMS.lastmatnr = -1;
index 0d2e7828d13eac59192915daa9168689cc50788b..ab8945368e3eaadbade20db80c8d26217abe97d2 100644 (file)
@@ -247,6 +247,7 @@ typedef struct View3D {
 #define RV3D_CLIPPING                          4
 #define RV3D_NAVIGATING                                8
 #define RV3D_GPULIGHT_UPDATE           16
+#define RV3D_IS_GAME_ENGINE                    32  /* runtime flag, used to check if LoD's should be used */
 
 /* RegionView3d->viewlock */
 #define RV3D_LOCKED                    (1 << 0)
index 193d7baad33ae472afa84e9ae204c654c52eb2b3..4a8629288383c7ef5da7591726e106e79ecac567 100644 (file)
@@ -1482,7 +1482,12 @@ int rna_Object_use_dynamic_topology_sculpting_get(PointerRNA *ptr)
 static void rna_Object_lod_distance_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        Object *ob = (Object *)ptr->id.data;
+
+#ifdef WITH_GAMEENGINE
        BKE_object_lod_sort(ob);
+#else
+       (void)ob;
+#endif
 }
 #else