Fix drawing of planar transfrom manipulators, update matrix code

This commit is contained in:
Julian Eisel 2017-04-07 16:02:45 +02:00
parent 2dd84c9570
commit 204e067111
7 changed files with 62 additions and 64 deletions

@ -44,6 +44,8 @@
#include "ED_screen.h"
#include "GPU_matrix.h"
#include "MEM_guardedalloc.h"
#include "RNA_access.h"
@ -73,12 +75,12 @@ static void arrow2d_draw_geom(ArrowManipulator2D *arrow, const float origin[2])
const float len = arrow->line_len;
const float draw_line_ofs = (arrow->manipulator.line_width * 0.5f) / arrow->manipulator.scale;
glPushMatrix();
glTranslatef(UNPACK2(origin), 0.0f);
glScalef(arrow->manipulator.scale, arrow->manipulator.scale, 0.0f);
glRotatef(RAD2DEGF(arrow->angle), 0.0f, 0.0f, 1.0f);
gpuPushMatrix();
gpuTranslate3f(UNPACK2(origin), 0.0f);
gpuScale3f(arrow->manipulator.scale, arrow->manipulator.scale, 0.0f);
gpuRotate3f(RAD2DEGF(arrow->angle), 0.0f, 0.0f, 1.0f);
/* local offset */
glTranslatef(arrow->manipulator.offset[0] + draw_line_ofs, arrow->manipulator.offset[1], 0.0f);
gpuTranslate3f(arrow->manipulator.offset[0] + draw_line_ofs, arrow->manipulator.offset[1], 0.0f);
/* TODO get rid of immediate mode */
glBegin(GL_LINES);
@ -91,7 +93,7 @@ static void arrow2d_draw_geom(ArrowManipulator2D *arrow, const float origin[2])
glVertex2f(0.0f, len + size * 1.7f);
glEnd();
glPopMatrix();
gpuPopMatrix();
}
static void manipulator_arrow2d_draw(const bContext *UNUSED(C), struct wmManipulator *manipulator)

@ -101,9 +101,12 @@ static void manipulator_arrow_get_final_pos(wmManipulator *manipulator, float r_
static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, const float color[4])
{
unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
bool unbind_shader = true;
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
if (arrow->style & MANIPULATOR_ARROW_STYLE_CROSS) {
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
immUniformColor4fv(color);
immBegin(GL_LINES, 4);
@ -112,8 +115,6 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
immVertex2f(pos, 0.f, -1.0);
immVertex2f(pos, 0.f, 1.0);
immEnd();
immUnbindProgram();
}
else if (arrow->style & MANIPULATOR_ARROW_STYLE_CONE) {
const float unitx = arrow->aspect[0];
@ -125,32 +126,13 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
{-unitx, unity, 0},
};
unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformColor4fv(color);
glLineWidth(arrow->manipulator.line_width);
const int vec_size = ARRAY_SIZE(vec);
immBegin(PRIM_LINE_STRIP, vec_size);
for (int i = 0; i < vec_size; i++) {
immVertex3fv(pos, vec[i]);
}
immEnd();
glLineWidth(1.0);
immUnbindProgram();
wm_manipulator_vec_draw(color, vec, ARRAY_SIZE(vec), pos, PRIM_LINE_STRIP);
}
else {
#ifdef USE_MANIPULATOR_CUSTOM_ARROWS
wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_arrow, select, color);
#else
unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR);
immUniformColor4fv(color);
const float vec[2][3] = {
{0.0f, 0.0f, 0.0f},
@ -158,15 +140,8 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
};
glLineWidth(arrow->manipulator.line_width);
wm_manipulator_vec_draw(color, vec, ARRAY_SIZE(vec), pos, PRIM_LINE_STRIP);
const int vec_size = ARRAY_SIZE(vec);
immBegin(PRIM_LINE_STRIP, vec_size);
for (int i = 0; i < vec_size; i++) {
immVertex3fv(pos, vec[i]);
}
immEnd();
glLineWidth(1.0);
/* *** draw arrow head *** */
@ -182,6 +157,7 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
/* draw cube */
immUnbindProgram();
unbind_shader = false;
wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_cube, select, color);
}
else {
@ -202,14 +178,15 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
if (use_lighting) {
glShadeModel(GL_FLAT);
}
immUnbindProgram();
}
gpuPopMatrix();
#endif /* USE_MANIPULATOR_CUSTOM_ARROWS */
}
if (unbind_shader) {
immUnbindProgram();
}
}
static void arrow_draw_intern(ArrowManipulator *arrow, const bool select, const bool highlight)

@ -45,6 +45,8 @@
#include "ED_screen.h"
#include "GPU_matrix.h"
#include "MEM_guardedalloc.h"
#include "RNA_access.h"
@ -187,13 +189,13 @@ static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipul
r.xmax = half_w;
r.ymax = half_h;
glPushMatrix();
glTranslatef(manipulator->origin[0] + manipulator->offset[0],
gpuPushMatrix();
gpuTranslate3f(manipulator->origin[0] + manipulator->offset[0],
manipulator->origin[1] + manipulator->offset[1], 0.0f);
if (cage->style & MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM)
glScalef(cage->scale[0], cage->scale[0], 1.0);
gpuScale3f(cage->scale[0], cage->scale[0], 1.0);
else
glScalef(cage->scale[0], cage->scale[1], 1.0);
gpuScale3f(cage->scale[0], cage->scale[1], 1.0);
if (w > h)
aspx = h / w;
@ -218,7 +220,7 @@ static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipul
w, h, cage->manipulator.line_width);
glLineWidth(1.0);
glPopMatrix();
gpuPopMatrix();
}
static int manipulator_rect_transform_get_cursor(wmManipulator *manipulator)

@ -38,6 +38,8 @@
#include "DNA_view3d_types.h"
#include "DNA_manipulator_types.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_select.h"
#include "MEM_guardedalloc.h"
@ -83,19 +85,17 @@ static void manipulator_primitive_draw_geom(
{
float (*verts)[3];
float vert_count;
unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
if (style == MANIPULATOR_PRIMITIVE_STYLE_PLANE) {
verts = verts_plane;
vert_count = ARRAY_SIZE(verts_plane);
}
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, verts);
glColor4fv(col_inner);
glDrawArrays(GL_QUADS, 0, vert_count);
glColor4fv(col_outer);
glDrawArrays(GL_LINE_LOOP, 0, vert_count);
glDisableClientState(GL_VERTEX_ARRAY);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
wm_manipulator_vec_draw(col_inner, verts, vert_count, pos, PRIM_QUADS);
wm_manipulator_vec_draw(col_outer, verts, vert_count, pos, PRIM_LINE_LOOP);
immUnbindProgram();
}
static void manipulator_primitive_draw_intern(
@ -120,19 +120,19 @@ static void manipulator_primitive_draw_intern(
copy_v3_v3(mat[3], prim->manipulator.origin);
mul_mat3_m4_fl(mat, prim->manipulator.scale);
glPushMatrix();
glMultMatrixf(mat);
gpuPushMatrix();
gpuMultMatrix3D(mat);
manipulator_color_get(&prim->manipulator, highlight, col_outer);
copy_v4_v4(col_inner, col_outer);
col_inner[3] *= 0.5f;
glEnable(GL_BLEND);
glTranslatef(UNPACK3(prim->manipulator.offset));
gpuTranslate3fv(prim->manipulator.offset);
manipulator_primitive_draw_geom(col_inner, col_outer, prim->style);
glDisable(GL_BLEND);
glPopMatrix();
gpuPopMatrix();
if (prim->manipulator.interaction_data) {
ManipulatorInteraction *inter = prim->manipulator.interaction_data;
@ -145,15 +145,15 @@ static void manipulator_primitive_draw_intern(
copy_v3_v3(mat[3], inter->init_origin);
mul_mat3_m4_fl(mat, inter->init_scale);
glPushMatrix();
glMultMatrixf(mat);
gpuPushMatrix();
gpuMultMatrix3D(mat);
glEnable(GL_BLEND);
glTranslatef(UNPACK3(prim->manipulator.offset));
gpuTranslate3f(UNPACK3(prim->manipulator.offset));
manipulator_primitive_draw_geom(col_inner, col_outer, prim->style);
glDisable(GL_BLEND);
glPopMatrix();
gpuPopMatrix();
}
}

@ -41,6 +41,7 @@
#include "GPU_batch.h"
#include "GPU_glew.h"
#include "GPU_immediate.h"
#include "MEM_guardedalloc.h"
@ -112,6 +113,18 @@ void wm_manipulator_geometryinfo_draw(const ManipulatorGeomInfo *info, const boo
Batch_discard_all(batch);
}
void wm_manipulator_vec_draw(
const float color[4], const float (*verts)[3], unsigned int vert_count,
unsigned int pos, unsigned int primitive_type)
{
immUniformColor4fv(color);
immBegin(primitive_type, vert_count);
for (int i = 0; i < vert_count; i++) {
immVertex3fv(pos, verts[i]);
}
immEnd();
}
/* Still unused */
wmManipulator *WM_manipulator_new(
void (*draw)(const bContext *C, wmManipulator *customdata),

@ -219,6 +219,9 @@ bool wm_manipulatormap_deselect_all(struct wmManipulatorMap *mmap, struct wmMani
/* Manipulator drawing */
void wm_manipulator_geometryinfo_draw(const struct ManipulatorGeomInfo *info, const bool select, const float color[4]);
void wm_manipulator_vec_draw(
const float color[4], const float (*verts)[3], unsigned int vert_count,
unsigned int pos, unsigned int primitive_type);
#endif /* __WM_MANIPULATOR_INTERN_H__ */

@ -42,6 +42,7 @@
#include "ED_view3d.h"
#include "GPU_glew.h"
#include "GPU_matrix.h"
#include "GPU_select.h"
#include "MEM_guardedalloc.h"
@ -256,11 +257,11 @@ static void manipulators_draw_list(const wmManipulatorMap *mmap, const bContext
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glPushMatrix();
glLoadIdentity();
gpuPushMatrix();
gpuLoadIdentity();
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glPopMatrix();
gpuPopMatrix();
}
/* draw_manipulators contains all visible manipulators - draw them */