OpenGL immediate mode: drawanimviz.c

Differential Revision: https://developer.blender.org/D2484

Part of T49043
This commit is contained in:
Luca Rood 2017-02-01 20:46:33 -02:00
parent 57573df0d3
commit 64b4a3185c
1 changed files with 81 additions and 44 deletions

View File

@ -51,6 +51,8 @@
#include "BIF_gl.h"
#include "GPU_immediate.h"
#include "ED_keyframes_draw.h"
@ -86,10 +88,11 @@ void draw_motion_paths_init(View3D *v3d, ARegion *ar)
* - User selected color for next frames
*/
static void set_motion_path_color(Scene *scene, bMotionPath *mpath, int i, short sel, int sfra, int efra,
float prev_color[3], float frame_color[3], float next_color[3])
float prev_color[3], float frame_color[3], float next_color[3], unsigned color)
{
int frame = sfra + i;
int blend_base = (abs(frame - CFRA) == 1) ? TH_CFRAME : TH_BACK; /* "bleed" cframe color to ease color blending */
unsigned char ubcolor[3];
#define SET_INTENSITY(A, B, C, min, max) (((1.0f - ((C - B) / (C - A))) * (max - min)) + min)
float intensity; /* how faint */
@ -97,7 +100,7 @@ static void set_motion_path_color(Scene *scene, bMotionPath *mpath, int i, short
if (frame < CFRA) {
if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
/* Custom color: previous frames color is darker than current frame */
glColor3fv(prev_color);
rgb_float_to_uchar(ubcolor, prev_color);
}
else {
/* black - before cfra */
@ -109,13 +112,14 @@ static void set_motion_path_color(Scene *scene, bMotionPath *mpath, int i, short
/* intensity = 0.8f; */
intensity = SET_INTENSITY(sfra, i, CFRA, 0.68f, 0.92f);
}
UI_ThemeColorBlend(TH_WIRE, blend_base, intensity);
UI_GetThemeColorBlend3ubv(TH_WIRE, blend_base, intensity, ubcolor);
}
}
else if (frame > CFRA) {
if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
/* Custom color: next frames color is equal to user selected color */
glColor3fv(next_color);
rgb_float_to_uchar(ubcolor, next_color);
}
else {
/* blue - after cfra */
@ -127,13 +131,14 @@ static void set_motion_path_color(Scene *scene, bMotionPath *mpath, int i, short
/* intensity = 0.8f; */
intensity = SET_INTENSITY(CFRA, i, efra, 0.68f, 0.92f);
}
UI_ThemeColorBlend(TH_BONE_POSE, blend_base, intensity);
UI_GetThemeColorBlend3ubv(TH_BONE_POSE, blend_base, intensity, ubcolor);
}
}
else {
if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
/* Custom color: current frame color is slightly darker than user selected color */
glColor3fv(frame_color);
rgb_float_to_uchar(ubcolor, frame_color);
}
else {
/* green - on cfra */
@ -143,9 +148,12 @@ static void set_motion_path_color(Scene *scene, bMotionPath *mpath, int i, short
else {
intensity = 0.99f;
}
UI_ThemeColorBlendShade(TH_CFRAME, TH_BACK, intensity, 10);
UI_GetThemeColorBlendShade3ubv(TH_CFRAME, TH_BACK, intensity, 10, ubcolor);
}
}
immAttrib3ubv(color, ubcolor);
#undef SET_INTENSITY
}
@ -231,42 +239,65 @@ void draw_motion_path_instance(Scene *scene,
/* set line thickness */
glLineWidth(mpath->line_thickness);
glBegin(GL_LINE_STRIP);
VertexFormat *format = immVertexFormat();
unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 3, NORMALIZE_INT_TO_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR);
immBegin(GL_LINE_STRIP, len);
for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
short sel = (pchan) ? (pchan->bone->flag & BONE_SELECTED) : (ob->flag & SELECT);
/* Set color */
set_motion_path_color(scene, mpath, i, sel, sfra, efra, prev_color, frame_color, next_color);
set_motion_path_color(scene, mpath, i, sel, sfra, efra, prev_color, frame_color, next_color, color);
/* draw a vertex with this color */
glVertex3fv(mpv->co);
immVertex3fv(pos, mpv->co);
}
glEnd();
immEnd();
immUnbindProgram();
/* back to old line thickness */
glLineWidth(old_width);
}
unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
/* Point must be bigger than line thickness */
glPointSize(mpath->line_thickness + 1.0);
/* draw little black point at each frame
* NOTE: this is not really visible/noticeable
*/
glBegin(GL_POINTS);
for (i = 0, mpv = mpv_start; i < len; i++, mpv++)
glVertex3fv(mpv->co);
glEnd();
/* draw little black point at each frame */
immUniformColor3ub(0, 0, 0);
immBegin(GL_POINTS, len);
for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
immVertex3fv(pos, mpv->co);
}
immEnd();
/* Draw little white dots at each framestep value or replace with custom color */
if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
glColor4fv(mpath->color);
immUniformColor3fv(mpath->color);
}
else {
UI_ThemeColor(TH_TEXT_HI);
immUniformThemeColor(TH_TEXT_HI);
}
glBegin(GL_POINTS);
for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize)
glVertex3fv(mpv->co);
glEnd();
immBegin(GL_POINTS, (len + stepsize - 1) / stepsize);
for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize) {
immVertex3fv(pos, mpv->co);
}
immEnd();
/* Draw big green dot where the current frame is
* NOTE: this is only done when keyframes are shown, since this adds similar types of clutter
@ -274,16 +305,18 @@ void draw_motion_path_instance(Scene *scene,
if ((avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) &&
(sfra < CFRA) && (CFRA <= efra))
{
UI_ThemeColor(TH_CFRAME);
glPointSize(mpath->line_thickness + 5.0);
glBegin(GL_POINTS);
immUniformThemeColor(TH_CFRAME);
immBegin(GL_POINTS, 1);
mpv = mpv_start + (CFRA - sfra);
glVertex3fv(mpv->co);
glEnd();
UI_ThemeColor(TH_TEXT_HI);
immVertex3fv(pos, mpv->co);
immEnd();
}
immUnbindProgram();
/* XXX, this isn't up to date but probably should be kept so. */
invert_m4_m4(ob->imat, ob->obmat);
@ -353,24 +386,28 @@ void draw_motion_path_instance(Scene *scene,
UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col);
col[3] = 255;
/* if custom, point must be bigger than line */
if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
glPointSize(mpath->line_thickness + 3.0);
}
else {
glPointSize(4.0f);
}
glColor3ubv(col);
/* point must be bigger than line */
glPointSize(mpath->line_thickness + 3.0);
pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformColor3ubv(col);
glBegin(GL_POINTS);
immBeginAtMost(GL_POINTS, len);
for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
int frame = sfra + i;
float mframe = (float)(frame);
if (BLI_dlrbTree_search_exact(&keys, compare_ak_cfraPtr, &mframe))
glVertex3fv(mpv->co);
if (BLI_dlrbTree_search_exact(&keys, compare_ak_cfraPtr, &mframe)) {
immVertex3fv(pos, mpv->co);
}
}
glEnd();
immEnd();
immUnbindProgram();
/* Draw frame numbers of keyframes */
if (avs->path_viewflag & MOTIONPATH_VIEW_KFNOS) {