diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-09 05:48:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-09 05:52:34 +0400 |
commit | 9de24c82bab8fc6f1b8810979ac492787d32a964 (patch) | |
tree | 3c2466ebd791a52859ce19ffee8ff5ed518a6061 | |
parent | b1f97a0cdb1bf6c7e0f80c6edb3182870625b9a6 (diff) |
View3D: disable LOD when game engine is disabled or ifdef'd
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 25 | ||||
-rw-r--r-- | source/blender/editors/object/object_lod.c | 11 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 23 | ||||
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/blender/gpu/SConscript | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 8 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_view3d_types.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 5 |
10 files changed, 67 insertions, 20 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 4b4deea044d..c0da816ca59 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -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); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 23af5bdf7ba..71b3e83f9de 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -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; diff --git a/source/blender/editors/object/object_lod.c b/source/blender/editors/object/object_lod.c index fdce59b10ff..d02b69ba5cf 100644 --- a/source/blender/editors/object/object_lod.c +++ b/source/blender/editors/object/object_lod.c @@ -51,7 +51,13 @@ 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; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index e7f94485664..13e74ece692 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -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)); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 9b455748713..2552be9b83b 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -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); diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 93c80c68f24..739deffa519 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -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() diff --git a/source/blender/gpu/SConscript b/source/blender/gpu/SConscript index c1c3fa92cb1..e9320f08eff 100644 --- a/source/blender/gpu/SConscript +++ b/source/blender/gpu/SConscript @@ -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']) diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 99f98f713ce..c22c4fbcdf4 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -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; diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 0d2e7828d13..ab8945368e3 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -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) diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 193d7baad33..4a862928838 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -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 |