[Bf-blender-cvs] [360cb87] blender2.8: OpenGL: modernize more volumetric gpencil drawing
Mike Erwin
noreply at git.blender.org
Thu Oct 6 18:45:32 CEST 2016
Commit: 360cb870071673d50a8f6e85fd1d49a9588f6105
Author: Mike Erwin
Date: Thu Oct 6 12:45:04 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB360cb870071673d50a8f6e85fd1d49a9588f6105
OpenGL: modernize more volumetric gpencil drawing
Main goal is to get rid of GLU.
Part of T49042, touches on T49043 and T49450
===================================================================
M source/blender/editors/gpencil/drawgpencil.c
===================================================================
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index cbfc141..a659ea6 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -101,7 +101,7 @@ typedef enum eDrawStrokeFlags {
#define F2UB(x) (unsigned char)(255.0f * x)
/* ----- Tool Buffer Drawing ------ */
-/* helper function to set color of buffer point */
+/* helper functions to set color of buffer point */
static void gp_set_tpoint_color(tGPspoint *pt, float ink[4])
{
float alpha = ink[3] * pt->strength;
@@ -109,6 +109,13 @@ static void gp_set_tpoint_color(tGPspoint *pt, float ink[4])
glColor4f(ink[0], ink[1], ink[2], alpha);
}
+static void gp_set_tpoint_varying_color(tGPspoint *pt, float ink[4], unsigned attrib_id)
+{
+ float alpha = ink[3] * pt->strength;
+ CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
+ immAttrib4ub(attrib_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha));
+}
+
/* helper functions to set color of point */
static void gp_set_point_color(bGPDspoint *pt, float ink[4])
{
@@ -231,46 +238,35 @@ static void gp_calc_2d_stroke_fxy(float pt[3], short sflag, int offsx, int offsy
* NOTE: the stroke buffer doesn't have any coordinate offsets/transforms
*/
static void gp_draw_stroke_volumetric_buffer(tGPspoint *points, int totpoints, short thickness,
- short dflag, short UNUSED(sflag), float ink[4])
+ short dflag, float ink[4])
{
- GLUquadricObj *qobj = gluNewQuadric();
- float modelview[4][4];
-
- tGPspoint *pt;
- int i;
-
/* error checking */
if ((points == NULL) || (totpoints <= 0))
return;
-
+
/* check if buffer can be drawn */
if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D))
return;
-
- /* get basic matrix - should be camera space (i.e "identity") */
- glGetFloatv(GL_MODELVIEW_MATRIX, (float *)modelview);
-
- /* draw points */
- glPushMatrix();
-
- for (i = 0, pt = points; i < totpoints; i++, pt++) {
- /* set the transformed position */
- // TODO: scale should change based on zoom level, which requires proper translation mult too!
- modelview[3][0] = pt->x;
- modelview[3][1] = pt->y;
-
- glLoadMatrixf((float *)modelview);
-
- /* draw the disk using the current state... */
- gp_set_tpoint_color(pt, ink);
- gluDisk(qobj, 0.0, pt->pressure * thickness, 32, 1);
-
-
- modelview[3][0] = modelview[3][1] = 0.0f;
+
+ VertexFormat *format = immVertexFormat();
+ unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+ unsigned size = add_attrib(format, "size", GL_FLOAT, 1, KEEP_FLOAT);
+ unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+ GPU_enable_program_point_size();
+ immBegin(GL_POINTS, totpoints);
+
+ tGPspoint *pt = points;
+ for (int i = 0; i < totpoints; i++, pt++) {
+ gp_set_tpoint_varying_color(pt, ink, color);
+ immAttrib1f(size, pt->pressure * thickness); /* TODO: scale based on view transform (zoom level) */
+ immVertex2f(pos, pt->x, pt->y);
}
- glPopMatrix();
- gluDeleteQuadric(qobj);
+ immEnd();
+ immUnbindProgram();
+ GPU_disable_program_point_size();
}
/* draw a 2D strokes in "volumetric" style */
@@ -1432,7 +1428,7 @@ static void gp_draw_data_layers(
*/
if (gpd->sflag & PC_COLOR_VOLUMETRIC) {
gp_draw_stroke_volumetric_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick,
- dflag, gpd->sbuffer_sflag, gpd->scolor);
+ dflag, gpd->scolor);
}
else {
gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag, gpd->scolor);
More information about the Bf-blender-cvs
mailing list