[Bf-blender-cvs] [d14258fd3f9] greasepencil-object: Merge branch 'blender2.8' into greasepencil-object
Antonio Vazquez
noreply at git.blender.org
Thu Apr 6 16:38:03 CEST 2017
Commit: d14258fd3f932c23de1e673c2ae8167582ff6112
Author: Antonio Vazquez
Date: Thu Apr 6 16:01:39 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBd14258fd3f932c23de1e673c2ae8167582ff6112
Merge branch 'blender2.8' into greasepencil-object
===================================================================
===================================================================
diff --cc source/blender/editors/gpencil/drawgpencil.c
index 3d2a83bb276,229aecc21ae..38e05315e69
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@@ -563,124 -501,85 +563,124 @@@ static void gp_triangulate_stroke_fill(
/* clear memory */
if (tmp_triangles) MEM_freeN(tmp_triangles);
if (points2d) MEM_freeN(points2d);
+ if (uv) MEM_freeN(uv);
}
-
-/* draw fills for shapes */
-static void gp_draw_stroke_fill(
- bGPdata *gpd, bGPDstroke *gps,
- int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4])
+/* add a new fill point and texture coordinates to vertex buffer */
+static void gp_add_filldata_tobuffer(bGPDspoint *pt, float uv[2], unsigned pos, unsigned texcoord, short flag,
+ int offsx, int offsy, int winx, int winy, const float diff_mat[4][4])
{
float fpt[3];
+ float co[2];
- BLI_assert(gps->totpoints >= 3);
+ mul_v3_m4v3(fpt, diff_mat, &pt->x);
+ /* if 2d, need conversion */
+ if (!flag & GP_STROKE_3DSPACE) {
+ gp_calc_2d_stroke_fxy(fpt, flag, offsx, offsy, winx, winy, co);
+ copy_v2_v2(fpt, co);
+ fpt[2] = 0.0f; /* 2d always is z=0.0f */
+ }
- bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps);
+ immAttrib2f(texcoord, uv[0], uv[1]); /* texture coordinates */
+ immVertex3fv(pos, fpt); /* position */
+}
- /* Triangulation fill if high quality flag is enabled */
- if (palcolor->flag & PC_COLOR_HQ_FILL) {
- /* Calculate triangles cache for filling area (must be done only after changes) */
- if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
- gp_triangulate_stroke_fill(gps);
- }
- BLI_assert(gps->tot_triangles >= 1);
+/* assign image texture for filling stroke */
+static int gp_set_filling_texture(Image *image, short flag)
+{
+ ImBuf *ibuf;
+ unsigned int *bind = &image->bindcode[TEXTARGET_TEXTURE_2D];
+ int error = GL_NO_ERROR;
+ ImageUser iuser = { NULL };
+ void *lock;
- unsigned int pos;
- if (gps->flag & GP_STROKE_3DSPACE) {
- pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- }
- else {
- pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- }
+ iuser.ok = true;
- immUniformColor4fv(color);
+ ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
- /* Draw all triangles for filling the polygon (cache must be calculated before) */
- immBegin(GL_TRIANGLES, gps->tot_triangles * 3);
- /* TODO: use batch instead of immediate mode, to share vertices */
+ if (ibuf == NULL || ibuf->rect == NULL) {
+ BKE_image_release_ibuf(image, ibuf, NULL);
+ return (int)GL_INVALID_OPERATION;
+ }
- bGPDtriangle *stroke_triangle = gps->triangles;
- bGPDspoint *pt;
+ GPU_create_gl_tex(bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D,
+ false, false, image);
- for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
- if (gps->flag & GP_STROKE_3DSPACE) {
- /* vertex 1 */
- pt = &gps->points[stroke_triangle->v1];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- immVertex3fv(pos, fpt);
- /* vertex 2 */
- pt = &gps->points[stroke_triangle->v2];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- immVertex3fv(pos, fpt);
- /* vertex 3 */
- pt = &gps->points[stroke_triangle->v3];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- immVertex3fv(pos, fpt);
- }
- else {
- float co[2];
- /* vertex 1 */
- pt = &gps->points[stroke_triangle->v1];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
- immVertex2fv(pos, co);
- /* vertex 2 */
- pt = &gps->points[stroke_triangle->v2];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
- immVertex2fv(pos, co);
- /* vertex 3 */
- pt = &gps->points[stroke_triangle->v3];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
- immVertex2fv(pos, co);
- }
- }
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ if (flag & PAC_COLOR_TEX_CLAMP) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ }
+ else {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ }
+ BKE_image_release_ibuf(image, ibuf, NULL);
+
+ return error;
+}
- immEnd();
- immUnbindProgram();
+/* draw fills for shapes */
+static void gp_draw_stroke_fill(
+ bGPdata *gpd, bGPDstroke *gps,
+ int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4])
+{
+ BLI_assert(gps->totpoints >= 3);
+ PaletteColor *palcolor = gps->palcolor;
+
+ /* Calculate triangles cache for filling area (must be done only after changes) */
+ if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
+ gp_triangulate_stroke_fill(gps);
}
+ BLI_assert(gps->tot_triangles >= 1);
+
+ VertexFormat *format = immVertexFormat();
- unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
- unsigned texcoord = add_attrib(format, "texCoord", GL_FLOAT, 2, KEEP_FLOAT);
++ unsigned pos = VertexFormat_add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
++ unsigned texcoord = VertexFormat_add_attrib(format, "texCoord", GL_FLOAT, 2, KEEP_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_GPENCIL_FILL);
+
+ immUniformColor4fv(color);
+ immUniform4fv("color2", palcolor->scolor);
+ immUniform1i("fill_type", palcolor->fill_style);
+ immUniform1f("mix_factor", palcolor->mix_factor);
+
+ immUniform1f("g_angle", palcolor->g_angle);
+ immUniform1f("g_radius", palcolor->g_radius);
+ immUniform1f("g_boxsize", palcolor->g_boxsize);
+ immUniform2fv("g_scale", palcolor->g_scale);
+ immUniform2fv("g_shift", palcolor->g_shift);
+
+ immUniform1f("t_angle", palcolor->t_angle);
+ immUniform2fv("t_scale", palcolor->t_scale);
+ immUniform2fv("t_shift", palcolor->t_shift);
+ immUniform1f("t_opacity", palcolor->t_opacity);
+ immUniform1i("t_mix", palcolor->flag & PAC_COLOR_TEX_MIX ? 1 : 0);
+ immUniform1i("t_flip", palcolor->flag & PAC_COLOR_FLIP_FILL ? 1 : 0);
+ /* image texture */
+ if ((palcolor->fill_style == FILL_STYLE_TEXTURE) || (palcolor->flag & PAC_COLOR_TEX_MIX)) {
+ gp_set_filling_texture(palcolor->ima, palcolor->flag);
+ }
+
+ /* Draw all triangles for filling the polygon (cache must be calculated before) */
+ immBegin(GL_TRIANGLES, gps->tot_triangles * 3);
+ /* TODO: use batch instead of immediate mode, to share vertices */
+
+ bGPDtriangle *stroke_triangle = gps->triangles;
+ for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
+ gp_add_filldata_tobuffer(&gps->points[stroke_triangle->v1], stroke_triangle->uv1,
+ pos, texcoord, gps->flag,
+ offsx, offsy, winx, winy, diff_mat);
+ gp_add_filldata_tobuffer(&gps->points[stroke_triangle->v2], stroke_triangle->uv2,
+ pos, texcoord, gps->flag,
+ offsx, offsy, winx, winy, diff_mat);
+ gp_add_filldata_tobuffer(&gps->points[stroke_triangle->v3], stroke_triangle->uv3,
+ pos, texcoord, gps->flag,
+ offsx, offsy, winx, winy, diff_mat);
+ }
+
+ immEnd();
+ immUnbindProgram();
}
/* ----- Existing Strokes Drawing (3D and Point) ------ */
@@@ -722,27 -621,29 +722,27 @@@ static void gp_draw_stroke_point
immUnbindProgram();
}
-/* draw a given stroke in 3d (i.e. in 3d-space), using simple ogl lines */
+/* draw a given stroke in 3d (i.e. in 3d-space) */
static void gp_draw_stroke_3d(const bGPDspoint *points, int totpoints, short thickness, bool UNUSED(debug),
- short UNUSED(sflag), const float diff_mat[4][4], const float ink[4], bool cyclic)
+ short UNUSED(sflag), const float diff_mat[4][4], const float ink[4], bool cyclic,
+ int winx, int winy, int offsx, int offsy)
{
+ float viewport[2] = { winx, winy };
+ float offset[2] = { offsx, offsy };
float curpressure = points[0].pressure;
float fpt[3];
- float cyclic_fpt[3];
- int draw_points = 0;
-
- /* if cyclic needs one vertex more */
- int cyclic_add = 0;
- if (cyclic) {
- ++cyclic_add;
- }
+ /* if cyclic needs more vertex */
+ int cyclic_add = (cyclic) ? 2 : 0;
VertexFormat *format = immVertexFormat();
- unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
- unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
- unsigned thickattrib = add_attrib(format, "thickness", GL_FLOAT, 1, KEEP_FLOAT);
- unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT);
- unsigned int color = VertexFormat_add_attrib(format, "color", COMP_U8, 4, NORMALIZE_INT_TO_FLOAT);
-
- immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR);
++ unsigned pos = VertexFormat_add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
++ unsigned color = VertexFormat_add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
++ unsigned thickattrib = VertexFormat_add_attrib(format, "thickness", GL_FLOAT, 1, KEEP_FLOAT);
- /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */
+ immBindBuiltinProgram(GPU_SHADER_GPENCIL_STROKE);
+ immUniform2fv("Viewport", viewport);
+ //immUniform2fv("Offset", offset);
/* draw stroke curve */
glLineWidth(max_ff(curpressure * thickness, 1.0f));
More information about the Bf-blender-cvs
mailing list