From a269287f36cfb99621fc8a5172c050f4a1046ba1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 Nov 2015 15:31:11 +1100 Subject: Cleanup: use single struct for freestyle globals Was shadowing local vars. --- source/blender/freestyle/FRS_freestyle.h | 16 ++++++---- .../freestyle/intern/application/AppView.cpp | 6 ++-- .../freestyle/intern/application/Controller.cpp | 12 ++++---- .../intern/blender_interface/FRS_freestyle.cpp | 34 +++++++++------------- .../freestyle/intern/geometry/GridHelpers.cpp | 8 ++--- .../freestyle/intern/python/BPy_Freestyle.cpp | 5 ++-- 6 files changed, 40 insertions(+), 41 deletions(-) (limited to 'source/blender') diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h index 975b1212695..039a75a2f0f 100644 --- a/source/blender/freestyle/FRS_freestyle.h +++ b/source/blender/freestyle/FRS_freestyle.h @@ -34,11 +34,17 @@ struct Material; struct FreestyleConfig; struct FreestyleLineStyle; -extern struct Scene *freestyle_scene; -extern float freestyle_viewpoint[3]; -extern float freestyle_mv[4][4]; -extern float freestyle_proj[4][4]; -extern int freestyle_viewport[4]; +struct FreestyleGlobals { + struct Scene *scene; + + /* camera information */ + float viewpoint[3]; + float mv[4][4]; + float proj[4][4]; + int viewport[4]; +}; + +extern struct FreestyleGlobals g_freestyle; /* Rendering */ void FRS_initialize(void); diff --git a/source/blender/freestyle/intern/application/AppView.cpp b/source/blender/freestyle/intern/application/AppView.cpp index 9de426b91ab..c331d1de9c9 100644 --- a/source/blender/freestyle/intern/application/AppView.cpp +++ b/source/blender/freestyle/intern/application/AppView.cpp @@ -110,7 +110,7 @@ real AppView::distanceToSceneCenter() { BBox bbox = _ModelRootNode->bbox(); - Vec3r v(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]); + Vec3r v(UNPACK3(g_freestyle.viewpoint)); v -= 0.5 * (bbox.getMin() + bbox.getMax()); return v.norm(); @@ -121,7 +121,7 @@ real AppView::znear() BBox bbox = _ModelRootNode->bbox(); Vec3r u = bbox.getMin(); Vec3r v = bbox.getMax(); - Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]); + Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint)); Vec3r w1(u[0], u[1], u[2]); Vec3r w2(v[0], u[1], u[2]); @@ -156,7 +156,7 @@ real AppView::zfar() BBox bbox = _ModelRootNode->bbox(); Vec3r u = bbox.getMin(); Vec3r v = bbox.getMax(); - Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]); + Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint)); Vec3r w1(u[0], u[1], u[2]); Vec3r w2(v[0], u[1], u[2]); diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index eb6a4702cba..136fec3dd1c 100644 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -289,14 +289,14 @@ int Controller::LoadMesh(Render *re, SceneRenderLayer *srl) if (_EnableViewMapCache) { NodeCamera *cam; - if (freestyle_proj[3][3] != 0.0) + if (g_freestyle.proj[3][3] != 0.0) cam = new NodeOrthographicCamera; else cam = new NodePerspectiveCamera; double proj[16]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - proj[i * 4 + j] = freestyle_proj[i][j]; + proj[i * 4 + j] = g_freestyle.proj[i][j]; } } cam->setProjectionMatrix(proj); @@ -477,7 +477,7 @@ void Controller::ComputeViewMap() // Restore the context of view: // we need to perform all these operations while the // 3D context is on. - Vec3f vp(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]); + Vec3f vp(UNPACK3(g_freestyle.viewpoint)); #if 0 if (G.debug & G_DEBUG_FREESTYLE) { @@ -487,7 +487,7 @@ void Controller::ComputeViewMap() real mv[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - mv[i][j] = freestyle_mv[i][j]; + mv[i][j] = g_freestyle.mv[i][j]; #if 0 if (G.debug & G_DEBUG_FREESTYLE) { cout << mv[i][j] << " "; @@ -509,7 +509,7 @@ void Controller::ComputeViewMap() real proj[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - proj[i][j] = freestyle_proj[i][j]; + proj[i][j] = g_freestyle.proj[i][j]; #if 0 if (G.debug & G_DEBUG_FREESTYLE) { cout << proj[i][j] << " "; @@ -525,7 +525,7 @@ void Controller::ComputeViewMap() int viewport[4]; for (int i = 0; i < 4; i++) - viewport[i] = freestyle_viewport[i]; + viewport[i] = g_freestyle.viewport[i]; #if 0 if (G.debug & G_DEBUG_FREESTYLE) { diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 2244e9196de..c18c5dad376 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -68,6 +68,8 @@ extern "C" { #define DEFAULT_SPHERE_RADIUS 1.0f #define DEFAULT_DKR_EPSILON 0.0f +struct FreestyleGlobals g_freestyle; + // Freestyle configuration static bool freestyle_is_initialized = false; static Config::Path *pathconfig = NULL; @@ -78,14 +80,6 @@ static AppView *view = NULL; static FreestyleLineSet lineset_buffer; static bool lineset_copied = false; -// camera information -float freestyle_viewpoint[3]; -float freestyle_mv[4][4]; -float freestyle_proj[4][4]; -int freestyle_viewport[4]; - -// current scene -Scene *freestyle_scene; static void load_post_callback(struct Main * /*main*/, struct ID * /*id*/, void * /*arg*/) { @@ -113,7 +107,7 @@ void FRS_initialize() view = new AppView; controller->setView(view); controller->Clear(); - freestyle_scene = NULL; + g_freestyle.scene = NULL; lineset_copied = false; BLI_callback_add(&load_post_callback_funcstore, BLI_CB_EVT_LOAD_POST); @@ -159,9 +153,9 @@ static void init_view(Render *re) break; } - freestyle_viewport[0] = freestyle_viewport[1] = 0; - freestyle_viewport[2] = width; - freestyle_viewport[3] = height; + g_freestyle.viewport[0] = g_freestyle.viewport[1] = 0; + g_freestyle.viewport[2] = width; + g_freestyle.viewport[3] = height; view->setWidth(width); view->setHeight(height); @@ -184,17 +178,15 @@ static void init_camera(Render *re) // Therefore, the view point (i.e., camera position) is at the origin, and // the model-view matrix is simply the identity matrix. - freestyle_viewpoint[0] = 0.0; - freestyle_viewpoint[1] = 0.0; - freestyle_viewpoint[2] = 0.0; + zero_v3(g_freestyle.viewpoint); - unit_m4(freestyle_mv); + unit_m4(g_freestyle.mv); - copy_m4_m4(freestyle_proj, re->winmat); + copy_m4_m4(g_freestyle.proj, re->winmat); #if 0 - print_m4("mv", freestyle_mv); - print_m4("proj", freestyle_proj); + print_m4("mv", g_freestyle.mv); + print_m4("proj", g_freestyle.proj); #endif } @@ -633,11 +625,11 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render) re->i.infostr = "Freestyle: Stroke rendering"; re->stats_draw(re->sdh, &re->i); re->i.infostr = NULL; - freestyle_scene = re->scene; + g_freestyle.scene = re->scene; controller->DrawStrokes(); freestyle_render = controller->RenderStrokes(re, true); controller->CloseFile(); - freestyle_scene = NULL; + g_freestyle.scene = NULL; // composite result FRS_composite_result(re, srl, freestyle_render); diff --git a/source/blender/freestyle/intern/geometry/GridHelpers.cpp b/source/blender/freestyle/intern/geometry/GridHelpers.cpp index a0543e56a36..d969d3e3024 100644 --- a/source/blender/freestyle/intern/geometry/GridHelpers.cpp +++ b/source/blender/freestyle/intern/geometry/GridHelpers.cpp @@ -41,10 +41,10 @@ void GridHelpers::getDefaultViewProscenium(real viewProscenium[4]) // borderZone describes a blank border outside the proscenium, but still inside the image area. // Only intended for exposing possible artifacts along or outside the proscenium edge during debugging. const real borderZone = 0.0; - viewProscenium[0] = freestyle_viewport[2] * (borderZone - bufferZone); - viewProscenium[1] = freestyle_viewport[2] * (1.0f - borderZone + bufferZone); - viewProscenium[2] = freestyle_viewport[3] * (borderZone - bufferZone); - viewProscenium[3] = freestyle_viewport[3] * (1.0f - borderZone + bufferZone); + viewProscenium[0] = g_freestyle.viewport[2] * (borderZone - bufferZone); + viewProscenium[1] = g_freestyle.viewport[2] * (1.0f - borderZone + bufferZone); + viewProscenium[2] = g_freestyle.viewport[3] * (borderZone - bufferZone); + viewProscenium[3] = g_freestyle.viewport[3] * (1.0f - borderZone + bufferZone); } GridHelpers::Transform::~Transform () diff --git a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp index d22632040f4..f8aef2a08ae 100644 --- a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp +++ b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp @@ -74,12 +74,13 @@ static char Freestyle_getCurrentScene___doc__[] = static PyObject *Freestyle_getCurrentScene(PyObject * /*self*/) { - if (!freestyle_scene) { + Scene *scene = g_freestyle.scene; + if (!scene) { PyErr_SetString(PyExc_TypeError, "current scene not available"); return NULL; } PointerRNA ptr_scene; - RNA_pointer_create(&freestyle_scene->id, &RNA_Scene, freestyle_scene, &ptr_scene); + RNA_pointer_create(&scene->id, &RNA_Scene, scene, &ptr_scene); return pyrna_struct_CreatePyObject(&ptr_scene); } -- cgit v1.2.3