Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2017-02-19 15:59:47 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-02-19 16:00:21 +0300
commitc8b7e7973af3d4675b0076103a727961e8c83ccc (patch)
tree4a65e40a6c1977875492bf7241b2d5e7fb71e9eb /source/blender/editors/transform/transform_manipulator.c
parent9f839a2ff52ea4e56c037c466cf1f173725f32b6 (diff)
OpenGL immediate mode: transform_manipulator.c
Diffstat (limited to 'source/blender/editors/transform/transform_manipulator.c')
-rw-r--r--source/blender/editors/transform/transform_manipulator.c466
1 files changed, 241 insertions, 225 deletions
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 33f065b4369..9072f963460 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -77,6 +77,8 @@
#include "transform.h"
#include "GPU_select.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
/* return codes for select, and drawing flags */
@@ -706,10 +708,10 @@ static void test_manipulator_axis(const bContext *C)
static float screen_aligned(RegionView3D *rv3d, float mat[4][4])
{
- glTranslate3fv(mat[3]);
+ gpuTranslate3fv(mat[3]);
/* sets view screen aligned */
- glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
+ gpuRotate3f(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
return len_v3(mat[0]); /* draw scale */
}
@@ -722,7 +724,7 @@ static float screen_aligned(RegionView3D *rv3d, float mat[4][4])
* nsides = amount of points in ring
* nrigns = amount of rings
*/
-static void partial_doughnut(float radring, float radhole, int start, int end, int nsides, int nrings)
+static void partial_doughnut(unsigned int pos, float radring, float radhole, int start, int end, int nsides, int nrings)
{
float theta, phi, theta1;
float cos_theta, sin_theta;
@@ -745,7 +747,7 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
sin_theta1 = sinf(theta1);
if (do_caps && i == start) { // cap
- glBegin(GL_POLYGON);
+ immBegin(GL_TRIANGLE_FAN, nsides+1);
phi = 0.0;
for (j = nsides; j >= 0; j--) {
float cos_phi, sin_phi, dist;
@@ -755,12 +757,12 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
sin_phi = sinf(phi);
dist = radhole + radring * cos_phi;
- glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
+ immVertex3f(pos, cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
}
- glEnd();
+ immEnd();
}
if (i >= start && i <= end) {
- glBegin(GL_QUAD_STRIP);
+ immBegin(GL_TRIANGLE_STRIP, (nsides+1) * 2);
phi = 0.0;
for (j = nsides; j >= 0; j--) {
float cos_phi, sin_phi, dist;
@@ -770,14 +772,14 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
sin_phi = sinf(phi);
dist = radhole + radring * cos_phi;
- glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
- glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi);
+ immVertex3f(pos, cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
+ immVertex3f(pos, cos_theta * dist, -sin_theta * dist, radring * sin_phi);
}
- glEnd();
+ immEnd();
}
if (do_caps && i == end) { // cap
- glBegin(GL_POLYGON);
+ immBegin(GL_TRIANGLE_FAN, nsides+1);
phi = 0.0;
for (j = nsides; j >= 0; j--) {
float cos_phi, sin_phi, dist;
@@ -787,9 +789,9 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
sin_phi = sinf(phi);
dist = radhole + radring * cos_phi;
- glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi);
+ immVertex3f(pos, cos_theta * dist, -sin_theta * dist, radring * sin_phi);
}
- glEnd();
+ immEnd();
}
@@ -858,7 +860,7 @@ static void manipulator_setcolor(View3D *v3d, char axis, int colcode, unsigned c
}
}
- glColor4ubv(col);
+ immUniformColor4ubv(col);
}
static void manipulator_axis_order(RegionView3D *rv3d, int r_axis_order[3])
@@ -878,7 +880,7 @@ static void manipulator_axis_order(RegionView3D *rv3d, int r_axis_order[3])
/* viewmatrix should have been set OK, also no shademode! */
static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int colcode,
int flagx, int flagy, int flagz, int axis,
- const bool is_picksel)
+ const bool is_picksel, unsigned int pos)
{
switch (axis) {
case 0:
@@ -891,10 +893,10 @@ static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int co
else {
manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->tw_idot[0]));
}
- glBegin(GL_LINES);
- glVertex3f(0.2f, 0.0f, 0.0f);
- glVertex3f(1.0f, 0.0f, 0.0f);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.2f, 0.0f, 0.0f);
+ immVertex3f(pos, 1.0f, 0.0f, 0.0f);
+ immEnd();
}
break;
case 1:
@@ -906,10 +908,10 @@ static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int co
else {
manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->tw_idot[1]));
}
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.2f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.0f, 0.2f, 0.0f);
+ immVertex3f(pos, 0.0f, 1.0f, 0.0f);
+ immEnd();
}
break;
case 2:
@@ -921,21 +923,21 @@ static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int co
else {
manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->tw_idot[2]));
}
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.2f);
- glVertex3f(0.0f, 0.0f, 1.0f);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.0f, 0.0f, 0.2f);
+ immVertex3f(pos, 0.0f, 0.0f, 1.0f);
+ immEnd();
}
break;
}
}
static void draw_manipulator_axes(View3D *v3d, RegionView3D *rv3d, int colcode,
int flagx, int flagy, int flagz,
- const int axis_order[3], const bool is_picksel)
+ const int axis_order[3], const bool is_picksel, unsigned int pos)
{
int i;
for (i = 0; i < 3; i++) {
- draw_manipulator_axes_single(v3d, rv3d, colcode, flagx, flagy, flagz, axis_order[i], is_picksel);
+ draw_manipulator_axes_single(v3d, rv3d, colcode, flagx, flagy, flagz, axis_order[i], is_picksel, pos);
}
}
@@ -945,8 +947,8 @@ static void preOrthoFront(const bool ortho, float twmat[4][4], int axis)
float omat[4][4];
copy_m4_m4(omat, twmat);
orthogonalize_m4(omat, axis);
- glPushMatrix();
- glMultMatrixf(omat);
+ gpuPushMatrix();
+ gpuMultMatrix3D(omat);
glFrontFace(is_negative_m4(omat) ? GL_CW : GL_CCW);
}
}
@@ -954,7 +956,7 @@ static void preOrthoFront(const bool ortho, float twmat[4][4], int axis)
static void postOrtho(const bool ortho)
{
if (ortho == false) {
- glPopMatrix();
+ gpuPopMatrix();
}
}
@@ -983,10 +985,18 @@ static void draw_manipulator_rotate(
glDisable(GL_DEPTH_TEST);
unit_m4(unitmat);
+
/* prepare for screen aligned draw */
size = len_v3(rv3d->twmat[0]);
- glPushMatrix();
- glTranslate3fv(rv3d->twmat[3]);
+ gpuMatrixBegin3D_legacy();
+ gpuPushMatrix();
+ gpuTranslate3fv(rv3d->twmat[3]);
+
+
+ const unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
if (arcs) {
/* clipplane makes nice handles, calc here because of multmatrix but with translate! */
@@ -995,29 +1005,29 @@ static void draw_manipulator_rotate(
glClipPlane(GL_CLIP_PLANE0, plane);
}
/* sets view screen aligned */
- glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
+ gpuRotate3f(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
/* Screen aligned help circle */
if (arcs) {
if (is_picksel == false) {
- UI_ThemeColorShade(TH_BACK, -30);
- drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat);
+ immUniformThemeColorShade(TH_BACK, -30);
+ imm_drawcircball(unitmat[3], size, unitmat, pos);
}
}
/* Screen aligned trackball rot circle */
if (drawflags & MAN_ROT_T) {
if (is_picksel) GPU_select_load_id(MAN_ROT_T);
- else UI_ThemeColor(TH_TRANSFORM);
+ else immUniformThemeColor(TH_TRANSFORM);
- drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
+ imm_drawcircball(unitmat[3], 0.2f * size, unitmat, pos);
}
/* Screen aligned view rot circle */
if (drawflags & MAN_ROT_V) {
if (is_picksel) GPU_select_load_id(MAN_ROT_V);
- else UI_ThemeColor(TH_TRANSFORM);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f * size, unitmat);
+ else immUniformThemeColor(TH_TRANSFORM);
+ imm_drawcircball(unitmat[3], 1.2f * size, unitmat, pos);
if (is_moving) {
float vec[3];
@@ -1025,14 +1035,15 @@ static void draw_manipulator_rotate(
vec[1] = 0; // XXX (float)(t->mouse.imval[1] - t->center2d[1]);
vec[2] = 0.0f;
normalize_v3_length(vec, 1.2f * size);
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3fv(vec);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.0f, 0.0f, 0.0f);
+ immVertex3fv(pos,vec);
+ immEnd();
}
}
- glPopMatrix();
+ gpuPopMatrix();
+ gpuPushMatrix();
ortho = is_orthogonal_m4(rv3d->twmat);
@@ -1041,14 +1052,14 @@ static void draw_manipulator_rotate(
copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
if (ortho) {
- glMultMatrixf(matt);
+ gpuMultMatrix3D(matt);
glFrontFace(is_negative_m4(matt) ? GL_CW : GL_CCW);
}
}
else {
if (ortho) {
glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
- glMultMatrixf(rv3d->twmat);
+ gpuMultMatrix3D(rv3d->twmat);
}
}
@@ -1060,28 +1071,28 @@ static void draw_manipulator_rotate(
if ((drawflags & MAN_ROT_X) || (is_moving && (drawflags & MAN_ROT_Z))) {
preOrthoFront(ortho, rv3d->twmat, 2);
manipulator_setcolor(v3d, 'X', colcode, 255);
- glBegin(GL_LINES);
- glVertex3f(0.2f, 0.0f, 0.0f);
- glVertex3f(1.0f, 0.0f, 0.0f);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.2f, 0.0f, 0.0f);
+ immVertex3f(pos, 1.0f, 0.0f, 0.0f);
+ immEnd();
postOrtho(ortho);
}
if ((drawflags & MAN_ROT_Y) || (is_moving && (drawflags & MAN_ROT_X))) {
preOrthoFront(ortho, rv3d->twmat, 0);
manipulator_setcolor(v3d, 'Y', colcode, 255);
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.2f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.0f, 0.2f, 0.0f);
+ immVertex3f(pos, 0.0f, 1.0f, 0.0f);
+ immEnd();
postOrtho(ortho);
}
if ((drawflags & MAN_ROT_Z) || (is_moving && (drawflags & MAN_ROT_Y))) {
preOrthoFront(ortho, rv3d->twmat, 1);
manipulator_setcolor(v3d, 'Z', colcode, 255);
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.2f);
- glVertex3f(0.0f, 0.0f, 1.0f);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.0f, 0.0f, 0.2f);
+ immVertex3f(pos, 0.0f, 0.0f, 1.0f);
+ immEnd();
postOrtho(ortho);
}
}
@@ -1095,7 +1106,7 @@ static void draw_manipulator_rotate(
preOrthoFront(ortho, matt, 2);
if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
else manipulator_setcolor(v3d, 'Z', colcode, 255);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
+ imm_drawcircball(unitmat[3], 1.0, unitmat, pos);
postOrtho(ortho);
}
/* X circle */
@@ -1103,9 +1114,9 @@ static void draw_manipulator_rotate(
preOrthoFront(ortho, matt, 0);
if (is_picksel) GPU_select_load_id(MAN_ROT_X);
else manipulator_setcolor(v3d, 'X', colcode, 255);
- glRotatef(90.0, 0.0, 1.0, 0.0);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
- glRotatef(-90.0, 0.0, 1.0, 0.0);
+ gpuRotate3f(90.0, 0.0, 1.0, 0.0);
+ imm_drawcircball(unitmat[3], 1.0, unitmat, pos);
+ gpuRotate3f(-90.0, 0.0, 1.0, 0.0);
postOrtho(ortho);
}
/* Y circle */
@@ -1113,9 +1124,9 @@ static void draw_manipulator_rotate(
preOrthoFront(ortho, matt, 1);
if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
else manipulator_setcolor(v3d, 'Y', colcode, 255);
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
- glRotatef(90.0, 1.0, 0.0, 0.0);
+ gpuRotate3f(-90.0, 1.0, 0.0, 0.0);
+ imm_drawcircball(unitmat[3], 1.0, unitmat, pos);
+ gpuRotate3f(90.0, 1.0, 0.0, 0.0);
postOrtho(ortho);
}
}
@@ -1128,7 +1139,7 @@ static void draw_manipulator_rotate(
preOrthoFront(ortho, rv3d->twmat, 2);
if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
else manipulator_setcolor(v3d, 'Z', colcode, 255);
- partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
+ partial_doughnut(pos, cusize / 4.0f, 1.0f, 0, 48, 8, 48);
postOrtho(ortho);
}
/* X circle */
@@ -1136,9 +1147,9 @@ static void draw_manipulator_rotate(
preOrthoFront(ortho, rv3d->twmat, 0);
if (is_picksel) GPU_select_load_id(MAN_ROT_X);
else manipulator_setcolor(v3d, 'X', colcode, 255);
- glRotatef(90.0, 0.0, 1.0, 0.0);
- partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
- glRotatef(-90.0, 0.0, 1.0, 0.0);
+ gpuRotate3f(90.0, 0.0, 1.0, 0.0);
+ partial_doughnut(pos, cusize / 4.0f, 1.0f, 0, 48, 8, 48);
+ gpuRotate3f(-90.0, 0.0, 1.0, 0.0);
postOrtho(ortho);
}
/* Y circle */
@@ -1146,9 +1157,9 @@ static void draw_manipulator_rotate(
preOrthoFront(ortho, rv3d->twmat, 1);
if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
else manipulator_setcolor(v3d, 'Y', colcode, 255);
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
- glRotatef(90.0, 1.0, 0.0, 0.0);
+ gpuRotate3f(-90.0, 1.0, 0.0, 0.0);
+ partial_doughnut(pos, cusize / 4.0f, 1.0f, 0, 48, 8, 48);
+ gpuRotate3f(90.0, 1.0, 0.0, 0.0);
postOrtho(ortho);
}
@@ -1160,55 +1171,57 @@ static void draw_manipulator_rotate(
/* Z handle on X axis */
if (drawflags & MAN_ROT_Z) {
preOrthoFront(ortho, rv3d->twmat, 2);
- glPushMatrix();
+ gpuPushMatrix();
if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
else manipulator_setcolor(v3d, 'Z', colcode, 255);
- partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
+ partial_doughnut(pos, 0.7f * cusize, 1.0f, 31, 33, 8, 64);
- glPopMatrix();
+ gpuPopMatrix();
postOrtho(ortho);
}
/* Y handle on X axis */
if (drawflags & MAN_ROT_Y) {
preOrthoFront(ortho, rv3d->twmat, 1);
- glPushMatrix();
+ gpuPushMatrix();
if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
else manipulator_setcolor(v3d, 'Y', colcode, 255);
- glRotatef(90.0, 1.0, 0.0, 0.0);
- glRotatef(90.0, 0.0, 0.0, 1.0);
- partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
+ gpuRotate3f(90.0, 1.0, 0.0, 0.0);
+ gpuRotate3f(90.0, 0.0, 0.0, 1.0);
+ partial_doughnut(pos, 0.7f * cusize, 1.0f, 31, 33, 8, 64);
- glPopMatrix();
+ gpuPopMatrix();
postOrtho(ortho);
}
/* X handle on Z axis */
if (drawflags & MAN_ROT_X) {
preOrthoFront(ortho, rv3d->twmat, 0);
- glPushMatrix();
+ gpuPushMatrix();
if (is_picksel) GPU_select_load_id(MAN_ROT_X);
else manipulator_setcolor(v3d, 'X', colcode, 255);
- glRotatef(-90.0, 0.0, 1.0, 0.0);
- glRotatef(90.0, 0.0, 0.0, 1.0);
- partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
+ gpuRotate3f(-90.0, 0.0, 1.0, 0.0);
+ gpuRotate3f(90.0, 0.0, 0.0, 1.0);
+ partial_doughnut(pos, 0.7f * cusize, 1.0f, 31, 33, 8, 64);
- glPopMatrix();
+ gpuPopMatrix();
postOrtho(ortho);
}
}
/* restore */
- glLoadMatrixf(rv3d->viewmat);
+ gpuPopMatrix();
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
+ immUnbindProgram();
+ gpuMatrixEnd();
}
-static void drawsolidcube(float size)
+static void drawsolidcube(unsigned int pos, float size)
{
const float cube[8][3] = {
{-1.0, -1.0, -1.0},
@@ -1220,53 +1233,26 @@ static void drawsolidcube(float size)
{ 1.0, 1.0, 1.0},
{ 1.0, 1.0, -1.0},
};
- float n[3] = {0.0f};
-
- glPushMatrix();
- glScalef(size, size, size);
-
- glBegin(GL_QUADS);
- n[0] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
- n[0] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[1] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
- n[1] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[0] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
- n[0] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[1] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
- n[1] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[2] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
- n[2] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[2] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
- glEnd();
-
- glPopMatrix();
+
+ gpuPushMatrix();
+ gpuScaleUniform(size);
+
+ immBegin(GL_TRIANGLES, 12 * 3);
+ immVertex3fv(pos, cube[0]); immVertex3fv(pos, cube[1]); immVertex3fv(pos, cube[2]);
+ immVertex3fv(pos, cube[0]); immVertex3fv(pos, cube[2]); immVertex3fv(pos, cube[3]);
+ immVertex3fv(pos, cube[0]); immVertex3fv(pos, cube[4]); immVertex3fv(pos, cube[5]);
+ immVertex3fv(pos, cube[0]); immVertex3fv(pos, cube[5]); immVertex3fv(pos, cube[1]);
+ immVertex3fv(pos, cube[4]); immVertex3fv(pos, cube[7]); immVertex3fv(pos, cube[6]);
+ immVertex3fv(pos, cube[4]); immVertex3fv(pos, cube[6]); immVertex3fv(pos, cube[5]);
+ immVertex3fv(pos, cube[7]); immVertex3fv(pos, cube[3]); immVertex3fv(pos, cube[2]);
+ immVertex3fv(pos, cube[7]); immVertex3fv(pos, cube[2]); immVertex3fv(pos, cube[6]);
+ immVertex3fv(pos, cube[1]); immVertex3fv(pos, cube[5]); immVertex3fv(pos, cube[6]);
+ immVertex3fv(pos, cube[1]); immVertex3fv(pos, cube[6]); immVertex3fv(pos, cube[2]);
+ immVertex3fv(pos, cube[7]); immVertex3fv(pos, cube[4]); immVertex3fv(pos, cube[0]);
+ immVertex3fv(pos, cube[7]); immVertex3fv(pos, cube[0]); immVertex3fv(pos, cube[3]);
+ immEnd();
+
+ gpuPopMatrix();
}
@@ -1286,6 +1272,13 @@ static void draw_manipulator_scale(
glDisable(GL_DEPTH_TEST);
+ const unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ gpuMatrixBegin3D_legacy();
+ gpuPushMatrix();
+
/* not in combo mode */
if ((combo & (V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE)) == 0) {
float size, unitmat[4][4];
@@ -1295,11 +1288,11 @@ static void draw_manipulator_scale(
if (is_picksel && shift == 0) GPU_select_load_id(MAN_SCALE_C);
else manipulator_setcolor(v3d, 'C', colcode, 255);
- glPushMatrix();
+ gpuPushMatrix();
size = screen_aligned(rv3d, rv3d->twmat);
unit_m4(unitmat);
- drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
- glPopMatrix();
+ imm_drawcircball(unitmat[3], 0.2f * size, unitmat, pos);
+ gpuPopMatrix();
dz = 1.0;
}
@@ -1312,11 +1305,11 @@ static void draw_manipulator_scale(
copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
- glMultMatrixf(matt);
+ gpuMultMatrix3D(matt);
glFrontFace(is_negative_m4(matt) ? GL_CW : GL_CCW);
}
else {
- glMultMatrixf(rv3d->twmat);
+ gpuMultMatrix3D(rv3d->twmat);
glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
}
@@ -1325,36 +1318,36 @@ static void draw_manipulator_scale(
/* in combo mode, this is always drawn as first type */
draw_manipulator_axes(v3d, rv3d, colcode,
drawflags & MAN_SCALE_X, drawflags & MAN_SCALE_Y, drawflags & MAN_SCALE_Z,
- axis_order, is_picksel);
+ axis_order, is_picksel, pos);
for (i = 0; i < 3; i++) {
switch (axis_order[i]) {
case 0: /* X cube */
if (drawflags & MAN_SCALE_X) {
- glTranslatef(dz, 0.0, 0.0);
+ gpuTranslate3f(dz, 0.0, 0.0);
if (is_picksel) GPU_select_load_id(MAN_SCALE_X);
else manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->tw_idot[0]));
- drawsolidcube(cusize);
- glTranslatef(-dz, 0.0, 0.0);
+ drawsolidcube(pos, cusize);
+ gpuTranslate3f(-dz, 0.0, 0.0);
}
break;
case 1: /* Y cube */
if (drawflags & MAN_SCALE_Y) {
- glTranslatef(0.0, dz, 0.0);
+ gpuTranslate3f(0.0, dz, 0.0);
if (is_picksel) GPU_select_load_id(MAN_SCALE_Y);
else manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->tw_idot[1]));
- drawsolidcube(cusize);
- glTranslatef(0.0, -dz, 0.0);
+ drawsolidcube(pos, cusize);
+ gpuTranslate3f(0.0, -dz, 0.0);
}
break;
case 2: /* Z cube */
if (drawflags & MAN_SCALE_Z) {
- glTranslatef(0.0, 0.0, dz);
+ gpuTranslate3f(0.0, 0.0, dz);
if (is_picksel) GPU_select_load_id(MAN_SCALE_Z);
else manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->tw_idot[2]));
- drawsolidcube(cusize);
- glTranslatef(0.0, 0.0, -dz);
+ drawsolidcube(pos, cusize);
+ gpuTranslate3f(0.0, 0.0, -dz);
}
break;
}
@@ -1366,25 +1359,28 @@ static void draw_manipulator_scale(
int shift = 0; // XXX
if (shift) {
- glTranslatef(0.0, -dz, 0.0);
+ gpuTranslate3f(0.0, -dz, 0.0);
GPU_select_load_id(MAN_SCALE_C);
/* TODO: set glPointSize before drawing center point */
- glBegin(GL_POINTS);
- glVertex3f(0.0, 0.0, 0.0);
- glEnd();
+ immBegin(GL_POINTS, 1);
+ immVertex3f(0.0, 0.0, 0.0);
+ immEnd();
}
}
#endif
/* restore */
- glLoadMatrixf(rv3d->viewmat);
+ gpuPopMatrix();
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CCW);
+
+ gpuMatrixEnd();
+ immUnbindProgram();
}
#define NSEGMENTS 8
-static void draw_cone(float len, float width)
+static void draw_cone(unsigned int pos, float len, float width)
{
/* a ring of vertices in the XY plane */
float p[NSEGMENTS][2];
@@ -1398,21 +1394,21 @@ static void draw_cone(float len, float width)
float ztop = 0.5f * len;
/* cone sides */
- glBegin(GL_TRIANGLE_FAN);
- glVertex3f(0, 0, ztop);
+ immBegin(GL_TRIANGLE_FAN, NSEGMENTS + 2);
+ immVertex3f(pos, 0, 0, ztop);
for (int i = 0; i < NSEGMENTS; ++i)
- glVertex3f(p[i][0], p[i][1], zbase);
- glVertex3f(p[0][0], p[0][1], zbase);
- glEnd();
+ immVertex3f(pos, p[i][0], p[i][1], zbase);
+ immVertex3f(pos, p[0][0], p[0][1], zbase);
+ immEnd();
/* end cap */
- glBegin(GL_TRIANGLE_FAN);
+ immBegin(GL_TRIANGLE_FAN, NSEGMENTS);
for (int i = NSEGMENTS - 1; i >= 0; --i)
- glVertex3f(p[i][0], p[i][1], zbase);
- glEnd();
+ immVertex3f(pos, p[i][0], p[i][1], zbase);
+ immEnd();
}
-static void draw_cylinder(float len, float width)
+static void draw_cylinder(unsigned int pos, float len, float width)
{
width *= 0.8f; // just for beauty
@@ -1428,24 +1424,24 @@ static void draw_cylinder(float len, float width)
float ztop = 0.5f * len;
/* cylinder sides */
- glBegin(GL_TRIANGLE_STRIP);
+ immBegin(GL_TRIANGLE_STRIP, (NSEGMENTS + 1) * 2);
for (int i = 0; i < NSEGMENTS; ++i) {
- glVertex3f(p[i][0], p[i][1], zbase);
- glVertex3f(p[i][0], p[i][1], ztop);
+ immVertex3f(pos, p[i][0], p[i][1], zbase);
+ immVertex3f(pos, p[i][0], p[i][1], ztop);
}
- glVertex3f(p[0][0], p[0][1], zbase);
- glVertex3f(p[0][0], p[0][1], ztop);
- glEnd();
+ immVertex3f(pos, p[0][0], p[0][1], zbase);
+ immVertex3f(pos, p[0][0], p[0][1], ztop);
+ immEnd();
/* end caps */
- glBegin(GL_TRIANGLE_FAN);
+ immBegin(GL_TRIANGLE_FAN, NSEGMENTS);
for (int i = NSEGMENTS - 1; i >= 0; --i)
- glVertex3f(p[i][0], p[i][1], zbase);
- glEnd();
- glBegin(GL_TRIANGLE_FAN);
+ immVertex3f(pos, p[i][0], p[i][1], zbase);
+ immEnd();
+ immBegin(GL_TRIANGLE_FAN, NSEGMENTS);
for (int i = 0; i < NSEGMENTS; ++i)
- glVertex3f(p[i][0], p[i][1], ztop);
- glEnd();
+ immVertex3f(pos, p[i][0], p[i][1], ztop);
+ immEnd();
}
#undef NSEGMENTS
@@ -1465,21 +1461,28 @@ static void draw_manipulator_translate(
manipulator_axis_order(rv3d, axis_order);
- // XXX if (moving) glTranslate3fv(t->vec);
+ // XXX if (moving) gpuTranslate3fv(t->vec);
glDisable(GL_DEPTH_TEST);
+ const unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ gpuMatrixBegin3D_legacy();
+ gpuPushMatrix();
+
/* center circle, do not add to selection when shift is pressed (planar constraint) */
if (is_picksel && shift == 0) GPU_select_load_id(MAN_TRANS_C);
else manipulator_setcolor(v3d, 'C', colcode, 255);
- glPushMatrix();
+ gpuPushMatrix();
size = screen_aligned(rv3d, rv3d->twmat);
unit_m4(unitmat);
- drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
- glPopMatrix();
+ imm_drawcircball(unitmat[3], 0.2f * size, unitmat, pos);
+ gpuPopMatrix();
/* and now apply matrix, we move to local matrix drawing */
- glMultMatrixf(rv3d->twmat);
+ gpuMultMatrix3D(rv3d->twmat);
/* axis */
GPU_select_load_id(-1);
@@ -1488,7 +1491,7 @@ static void draw_manipulator_translate(
if ((combo & V3D_MANIP_SCALE) == 0 || colcode == MAN_GHOST) {
draw_manipulator_axes(v3d, rv3d, colcode,
drawflags & MAN_TRANS_X, drawflags & MAN_TRANS_Y, drawflags & MAN_TRANS_Z,
- axis_order, is_picksel);
+ axis_order, is_picksel, pos);
}
/* offset in combo mode, for rotate a bit more */
@@ -1500,42 +1503,45 @@ static void draw_manipulator_translate(
switch (axis_order[i]) {
case 0: /* Z Cone */
if (drawflags & MAN_TRANS_Z) {
- glPushMatrix();
- glTranslatef(0.0, 0.0, dz);
+ gpuPushMatrix();
+ gpuTranslate3f(0.0, 0.0, dz);
if (is_picksel) GPU_select_load_id(MAN_TRANS_Z);
else manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->tw_idot[2]));
- draw_cone(cylen, cywid);
- glPopMatrix();
+ draw_cone(pos, cylen, cywid);
+ gpuPopMatrix();
}
break;
case 1: /* X Cone */
if (drawflags & MAN_TRANS_X) {
- glPushMatrix();
- glTranslatef(dz, 0.0, 0.0);
+ gpuPushMatrix();
+ gpuTranslate3f(dz, 0.0, 0.0);
if (is_picksel) GPU_select_load_id(MAN_TRANS_X);
else manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->tw_idot[0]));
- glRotatef(90.0, 0.0, 1.0, 0.0);
- draw_cone(cylen, cywid);
- glPopMatrix();
+ gpuRotate3f(90.0, 0.0, 1.0, 0.0);
+ draw_cone(pos, cylen, cywid);
+ gpuPopMatrix();
}
break;
case 2: /* Y Cone */
if (drawflags & MAN_TRANS_Y) {
- glPushMatrix();
- glTranslatef(0.0, dz, 0.0);
+ gpuPushMatrix();
+ gpuTranslate3f(0.0, dz, 0.0);
if (is_picksel) GPU_select_load_id(MAN_TRANS_Y);
else manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->tw_idot[1]));
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- draw_cone(cylen, cywid);
- glPopMatrix();
+ gpuRotate3f(-90.0, 1.0, 0.0, 0.0);
+ draw_cone(pos, cylen, cywid);
+ gpuPopMatrix();
}
break;
}
}
- glLoadMatrixf(rv3d->viewmat);
+ gpuPopMatrix();
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
+
+ immUnbindProgram();
+ gpuMatrixEnd();
}
static void draw_manipulator_rotate_cyl(
@@ -1553,8 +1559,15 @@ static void draw_manipulator_rotate_cyl(
manipulator_axis_order(rv3d, axis_order);
+ const unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ gpuMatrixBegin3D_legacy();
+ gpuPushMatrix();
+
/* prepare for screen aligned draw */
- glPushMatrix();
+ gpuPushMatrix();
size = screen_aligned(rv3d, rv3d->twmat);
glDisable(GL_DEPTH_TEST);
@@ -1566,8 +1579,8 @@ static void draw_manipulator_rotate_cyl(
unit_m4(unitmat);
if (is_picksel) GPU_select_load_id(MAN_ROT_V);
- UI_ThemeColor(TH_TRANSFORM);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f * size, unitmat);
+ immUniformThemeColor(TH_TRANSFORM);
+ imm_drawcircball(unitmat[3], 1.2f * size, unitmat, pos);
if (is_moving) {
float vec[3];
@@ -1575,13 +1588,13 @@ static void draw_manipulator_rotate_cyl(
vec[1] = 0; // XXX (float)(t->mouse.imval[1] - t->center2d[1]);
vec[2] = 0.0f;
normalize_v3_length(vec, 1.2f * size);
- glBegin(GL_LINES);
- glVertex3f(0.0, 0.0, 0.0);
- glVertex3fv(vec);
- glEnd();
+ immBegin(GL_LINES, 2);
+ immVertex3f(pos, 0.0, 0.0, 0.0);
+ immVertex3fv(pos, vec);
+ immEnd();
}
}
- glPopMatrix();
+ gpuPopMatrix();
/* apply the transform delta */
if (is_moving) {
@@ -1590,10 +1603,10 @@ static void draw_manipulator_rotate_cyl(
// XXX if (t->flag & T_USES_MANIPULATOR) {
// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
// XXX }
- glMultMatrixf(matt);
+ gpuMultMatrix3D(matt);
}
else {
- glMultMatrixf(rv3d->twmat);
+ gpuMultMatrix3D(rv3d->twmat);
}
glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
@@ -1605,7 +1618,7 @@ static void draw_manipulator_rotate_cyl(
if ((combo & V3D_MANIP_SCALE) == 0) {
draw_manipulator_axes(v3d, rv3d, colcode,
drawflags & MAN_ROT_X, drawflags & MAN_ROT_Y, drawflags & MAN_ROT_Z,
- axis_order, is_picksel);
+ axis_order, is_picksel, pos);
}
}
@@ -1613,43 +1626,46 @@ static void draw_manipulator_rotate_cyl(
switch (axis_order[i]) {
case 0: /* X cylinder */
if (drawflags & MAN_ROT_X) {
- glPushMatrix();
- glTranslatef(1.0, 0.0, 0.0);
+ gpuPushMatrix();
+ gpuTranslate3f(1.0, 0.0, 0.0);
if (is_picksel) GPU_select_load_id(MAN_ROT_X);
- glRotatef(90.0, 0.0, 1.0, 0.0);
+ gpuRotate3f(90.0, 0.0, 1.0, 0.0);
manipulator_setcolor(v3d, 'X', colcode, 255);
- draw_cylinder(cylen, cywid);
- glPopMatrix();
+ draw_cylinder(pos, cylen, cywid);
+ gpuPopMatrix();
}
break;
case 1: /* Y cylinder */
if (drawflags & MAN_ROT_Y) {
- glPushMatrix();
- glTranslatef(0.0, 1.0, 0.0);
+ gpuPushMatrix();
+ gpuTranslate3f(0.0, 1.0, 0.0);
if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
- glRotatef(-90.0, 1.0, 0.0, 0.0);
+ gpuRotate3f(-90.0, 1.0, 0.0, 0.0);
manipulator_setcolor(v3d, 'Y', colcode, 255);
- draw_cylinder(cylen, cywid);
- glPopMatrix();
+ draw_cylinder(pos, cylen, cywid);
+ gpuPopMatrix();
}
break;
case 2: /* Z cylinder */
if (drawflags & MAN_ROT_Z) {
- glPushMatrix();
- glTranslatef(0.0, 0.0, 1.0);
+ gpuPushMatrix();
+ gpuTranslate3f(0.0, 0.0, 1.0);
if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
manipulator_setcolor(v3d, 'Z', colcode, 255);
- draw_cylinder(cylen, cywid);
- glPopMatrix();
+ draw_cylinder(pos, cylen, cywid);
+ gpuPopMatrix();
}
break;
}
}
/* restore */
- glLoadMatrixf(rv3d->viewmat);
+ gpuPopMatrix();
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
+
+ gpuMatrixEnd();
+ immUnbindProgram();
}