[Bf-blender-cvs] [5de33c3] blender2.8: cleanup: C99 for view3d_draw
Mike Erwin
noreply at git.blender.org
Mon Dec 5 02:13:10 CET 2016
Commit: 5de33c3b645e9e898ff4ced79d44bf8a68a62b93
Author: Mike Erwin
Date: Sun Dec 4 20:11:12 2016 -0500
Branches: blender2.8
https://developer.blender.org/rB5de33c3b645e9e898ff4ced79d44bf8a68a62b93
cleanup: C99 for view3d_draw
Mostly for clarity & to declare things close to where they are used.
I'm getting ready to do substantial work in these files.
===================================================================
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/editors/space_view3d/view3d_draw_legacy.c
===================================================================
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 2012097..91d88ee 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -190,6 +190,7 @@ static void view3d_main_region_setup_view(Scene *scene, View3D *v3d, ARegion *ar
ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat);
/* set for opengl */
+ /* TODO(merwin): transition to GPU_matrix API */
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(rv3d->winmat);
glMatrixMode(GL_MODELVIEW);
@@ -1600,7 +1601,6 @@ static void draw_all_objects(const bContext *C, ARegion *ar, const bool only_dep
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
- Base *base;
if (only_depth)
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
@@ -1612,7 +1612,7 @@ static void draw_all_objects(const bContext *C, ARegion *ar, const bool only_dep
v3d->zbuf = true;
}
- for (base = scene->base.first; base; base = base->next) {
+ for (Base *base = scene->base.first; base; base = base->next) {
if (v3d->lay & base->lay) {
/* dupli drawing */
if (base->object->transflag & OB_DUPLI)
@@ -1658,9 +1658,6 @@ static void view3d_draw_prerender_buffers(const bContext *C, ARegion *ar, DrawDa
*/
static void view3d_draw_solid_plates(const bContext *C, ARegion *ar, DrawData *draw_data)
{
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
-
/* realtime plates */
if ((!draw_data->is_render) || draw_data->clip_border) {
view3d_draw_background(C);
@@ -1671,6 +1668,9 @@ static void view3d_draw_solid_plates(const bContext *C, ARegion *ar, DrawData *d
/* offline plates*/
if (draw_data->is_render) {
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+
view3d_draw_render_draw(C, scene, ar, v3d, draw_data->clip_border, &draw_data->border_rect);
}
@@ -1698,14 +1698,10 @@ static void view3d_draw_non_meshes(const bContext *C, ARegion *ar)
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = ar->regiondata;
- Object *ob_act = CTX_data_active_object(C);
- Base *base;
bool is_boundingbox = ((v3d->drawtype == OB_BOUNDBOX) ||
((v3d->drawtype == OB_RENDER) && (v3d->prev_drawtype == OB_BOUNDBOX)));
- unsigned char ob_wire_col[4]; /* dont initialize this */
-
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
/* TODO Viewport
@@ -1713,10 +1709,11 @@ static void view3d_draw_non_meshes(const bContext *C, ARegion *ar)
* for now let's avoid writing again to zbuffer to prevent glitches
*/
- for (base = scene->base.first; base; base = base->next) {
+ for (Base *base = scene->base.first; base; base = base->next) {
if (v3d->lay & base->lay) {
Object *ob = base->object;
+ unsigned char ob_wire_col[4];
draw_object_wire_color(scene, base, ob_wire_col);
view3d_draw_non_mesh(scene, ob, base, v3d, rv3d, is_boundingbox, ob_wire_col);
}
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c
index c66eabd..ea24a1e 100644
--- a/source/blender/editors/space_view3d/view3d_draw_legacy.c
+++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c
@@ -167,9 +167,8 @@ void ED_view3d_clipping_set(RegionView3D *rv3d)
{
double plane[4];
const unsigned int tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
- unsigned int a;
- for (a = 0; a < tot; a++) {
+ for (unsigned a = 0; a < tot; a++) {
copy_v4db_v4fl(plane, rv3d->clip[a]);
glClipPlane(GL_CLIP_PLANE0 + a, plane);
glEnable(GL_CLIP_PLANE0 + a);
@@ -179,17 +178,13 @@ void ED_view3d_clipping_set(RegionView3D *rv3d)
/* use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set */
void ED_view3d_clipping_disable(void)
{
- unsigned int a;
-
- for (a = 0; a < 6; a++) {
+ for (unsigned a = 0; a < 6; a++) {
glDisable(GL_CLIP_PLANE0 + a);
}
}
void ED_view3d_clipping_enable(void)
{
- unsigned int a;
-
- for (a = 0; a < 6; a++) {
+ for (unsigned a = 0; a < 6; a++) {
glEnable(GL_CLIP_PLANE0 + a);
}
}
@@ -399,8 +394,6 @@ static void draw_rotation_guide(RegionView3D *rv3d)
const float s = 0.05f * scale;
const float step = 2.0f * (float)(M_PI / ROT_AXIS_DETAIL);
- float angle;
- int i;
float q[4]; /* rotate ring so it's perpendicular to axis */
const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f;
@@ -416,7 +409,8 @@ static void draw_rotation_guide(RegionView3D *rv3d)
immBegin(GL_LINE_LOOP, ROT_AXIS_DETAIL);
color[3] = 63; /* somewhat faint */
immAttrib4ubv(col, color);
- for (i = 0, angle = 0.0f; i < ROT_AXIS_DETAIL; ++i, angle += step) {
+ float angle = 0.0f;
+ for (int i = 0; i < ROT_AXIS_DETAIL; ++i, angle += step) {
float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f};
if (!upright) {
@@ -529,7 +523,6 @@ static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
else {
name = (rv3d->persp == RV3D_ORTHO) ? IFACE_("User Ortho") : IFACE_("User Persp");
}
- break;
}
return name;
@@ -570,7 +563,6 @@ static void draw_selected_name(Scene *scene, Object *ob, rcti *rect)
const char *msg_sep = " : ";
char info[300];
- const char *markern;
char *s = info;
short offset = 1.5f * UI_UNIT_X + rect->xmin;
@@ -586,7 +578,7 @@ static void draw_selected_name(Scene *scene, Object *ob, rcti *rect)
*/
/* get name of marker on current frame (if available) */
- markern = BKE_scene_find_marker_name(scene, cfra);
+ const char *markern = BKE_scene_find_marker_name(scene, cfra);
/* check if there is an object */
if (ob) {
@@ -615,9 +607,6 @@ static void draw_selected_name(Scene *scene, Object *ob, rcti *rect)
}
}
else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
- Key *key = NULL;
- KeyBlock *kb = NULL;
-
/* try to display active bone and active shapekey too (if they exist) */
if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
@@ -633,9 +622,9 @@ static void draw_selected_name(Scene *scene, Object *ob, rcti *rect)
}
}
- key = BKE_key_from_object(ob);
+ Key *key = BKE_key_from_object(ob);
if (key) {
- kb = BLI_findlink(&key->block, ob->shapenr - 1);
+ KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1);
if (kb) {
s += BLI_strcpy_rlen(s, msg_sep);
s += BLI_strcpy_rlen(s, kb->name);
@@ -808,7 +797,6 @@ void view3d_opengl_read_pixels(ARegion *ar, int x, int y, int w, int h, int form
/* XXX depth reading exception, for code not using gpu offscreen */
static void view3d_opengl_read_Z_pixels(ARegion *ar, int x, int y, int w, int h, int format, int type, void *data)
{
-
glReadPixels(ar->winrct.xmin + x, ar->winrct.ymin + y, w, h, format, type, data);
}
@@ -830,28 +818,26 @@ int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist)
/* samples a single pixel (copied from vpaint) */
unsigned int ED_view3d_backbuf_sample(ViewContext *vc, int x, int y)
{
- unsigned int col;
-
if (x >= vc->ar->winx || y >= vc->ar->winy) {
return 0;
}
ED_view3d_backbuf_validate(vc);
+ unsigned int col;
view3d_opengl_read_pixels(vc->ar, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
glReadBuffer(GL_BACK);
-
+
if (ENDIAN_ORDER == B_ENDIAN) {
BLI_endian_switch_uint32(&col);
}
-
+
return GPU_select_to_index(col);
}
/* reads full rect, converts indices */
ImBuf *ED_view3d_backbuf_read(ViewContext *vc, int xmin, int ymin, int xmax, int ymax)
{
- struct ImBuf *ibuf_clip;
/* clip */
const rcti clip = {
max_ii(xmin, 0), min_ii(xmax, vc->ar->winx - 1),
@@ -866,7 +852,7 @@ ImBuf *ED_view3d_backbuf_read(ViewContext *vc, int xmin, int ymin, int xmax, int
return NULL;
}
- ibuf_clip = IMB_allocImBuf(size_clip[0], size_clip[1], 32, IB_rect);
+ ImBuf *ibuf_clip = IMB_allocImBuf(size_clip[0], size_clip[1], 32, IB_rect);
ED_view3d_backbuf_validate(vc);
@@ -889,12 +875,11 @@ ImBuf *ED_view3d_backbuf_read(ViewContext *vc, int xmin, int ymin, int xmax, int
}
else {
/* put clipped result into a non-clipped buffer */
- struct ImBuf *ibuf_full;
const int size[2] = {
(xmax - xmin + 1),
(ymax - ymin + 1)};
- ibuf_full = IMB_allocImBuf(size[0], size[1], 32, IB_rect);
+ ImBuf *ibuf_full = IMB_allocImBuf(size[0], size[1], 32, IB_rect);
IMB_rectcpy(
ibuf_full, ibuf_clip,
@@ -911,35 +896,31 @@ unsigned int ED_view3d_backbuf_sample_rect(
ViewContext *vc, const int mval[2], int size,
unsigned int min, unsigned int max, float *r_dist)
{
- struct ImBuf *buf;
- const unsigned int *bufmin, *bufmax, *tbuf;
- int minx, miny;
- int a, b, rc, nr, amount, dirvec[4][2];
- unsigned int index = 0;
+ int dirvec[4][2];
- amount = (size - 1) / 2;
+ const int amount = (size - 1) / 2;
- minx = mval[0] - (amount + 1);
- miny = mval[1] - (amount + 1);
- buf = ED_view3d_backbuf_read(vc, minx, miny, minx + size - 1, miny + size - 1);
+ const int minx = mval[0] - (amount + 1);
+ const int miny = mval[1] - (amount + 1);
+ ImBuf *buf = ED_view3d_backbuf_read(vc, minx, miny, minx + size - 1, miny + size - 1);
if (!buf) return 0;
- rc = 0;
+ unsigned index = 0;
+ int rc = 0;
dirvec[0][0] = 1; dirvec[0][1] = 0;
dirvec[1][0] = 0; dirvec[1][1] = -size;
dirvec[2][0] = -1; dirvec[2][1] = 0;
dirvec[3][0] = 0; dirvec[3][1] = size;
- bufmin = buf->rect;
- tbuf = buf->rect;
- bufmax = buf->rect + size * size;
+ const unsigned *bufmin = buf->rect;
+ const unsigned *tbuf = buf->rect;
+ const unsigned *bufmax = buf->rect + size * size;
tbuf += amount * size + amount;
- for (nr = 1; nr <= size; nr++) {
-
- for (a = 0; a < 2; a++) {
- for (b = 0; b < nr; b++) {
+ for (int nr = 1; nr <= size; nr++) {
+ for (int a = 0; a < 2; a++) {
+ for (int b = 0; b < nr; b++) {
if (*tbuf && *tbuf >= min && *tbuf < max) {
/* we got a hit */
@@ -997,10 +978,9 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
const bool do_foreground, const bool do_camera_frame)
{
RegionView3D *rv3d = ar->regiondata;
- BGpic *bgpic;
int fg_flag = do_foreground ? V3D_B
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list