[Bf-blender-cvs] [dbe23c5456] blender2.8: OpenGL immediate mode: sequencer_draw.c

Luca Rood noreply at git.blender.org
Wed Feb 15 20:14:47 CET 2017


Commit: dbe23c5456496a179b956b545c24c311b69c1c62
Author: Luca Rood
Date:   Wed Feb 8 02:43:17 2017 -0200
Branches: blender2.8
https://developer.blender.org/rBdbe23c5456496a179b956b545c24c311b69c1c62

OpenGL immediate mode: sequencer_draw.c

Other than the general conversion:
* Made some slight aesthetic improvements.
** Removed gradients.
** Replaced stipples with transparency for hidden strips.
** Made strip borders less harsh.
** Removed stripes from offsets and made them brighter.
* Made only the visible parts of waveforms be drawn.
* Fixed a few drawing bugs.
** Background was not being drawn when buffer is NULL, and no
grease pencil is being drawn.
** Offset drawing ignored strip visibility.

Also, note that diagonal stripes for locked and error strips, are still
being drawn with the old api, as they await a new shader in order to
be converted.

Part of 49043

===================================================================

M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_sequencer/sequencer_intern.h

===================================================================

diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 09629b99e1..9c9f47d55f 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -191,25 +191,35 @@ void color3ubv_from_seq(Scene *curscene, Sequence *seq, unsigned char col[3])
 	}
 }
 
-static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequence *seq, float x1, float y1, float x2, float y2, float stepsize)
+static void drawseqwave(View2D *v2d, const bContext *C, SpaceSeq *sseq, Scene *scene, Sequence *seq,
+                        float x1, float y1, float x2, float y2, float stepsize, unsigned int pos)
 {
 	/*
 	 * x1 is the starting x value to draw the wave,
 	 * x2 the end x value, same for y1 and y2
 	 * stepsize is width of a pixel.
 	 */
+
+	/* offset x1 and x2 values, to match view min/max, if strip is out of bounds */
+	int x1_offset = max_ff(v2d->cur.xmin, x1);
+	int x2_offset = min_ff(v2d->cur.xmax + 1.0f, x2);
+
 	if (seq->sound && ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) {
-		int i, j, pos;
-		int length = floor((x2 - x1) / stepsize) + 1;
-		float ymid = (y1 + y2) / 2;
-		float yscale = (y2 - y1) / 2;
+		int i, j, p;
+		int length = floor((x2_offset - x1_offset) / stepsize) + 1;
+		float ymid = (y1 + y2) / 2.0f;
+		float yscale = (y2 - y1) / 2.0f;
 		float samplestep;
 		float startsample, endsample;
 		float value1, value2;
 		bSound *sound = seq->sound;
 		
 		SoundWaveform *waveform;
-		
+
+		if (length < 2) {
+			return;
+		}
+
 		if (!sound->spinlock) {
 			sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
 			BLI_spin_init(sound->spinlock);
@@ -242,21 +252,27 @@ static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequenc
 		endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
 		samplestep = (endsample - startsample) * stepsize / (x2 - x1);
 
-		if (length > floor((waveform->length - startsample) / samplestep))
-			length = floor((waveform->length - startsample) / samplestep);
+		length = min_ii(floor((waveform->length - startsample) / samplestep), length);
+
+		if (length < 2) {
+			return;
+		}
+
+		immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5);
 
-		glColor4f(1.0f, 1.0f, 1.0f, 0.5);
 		glEnable(GL_BLEND);
-		glBegin(GL_TRIANGLE_STRIP);
+
+		immBegin(GL_TRIANGLE_STRIP, length * 2);
+
 		for (i = 0; i < length; i++) {
-			float sampleoffset = startsample + i * samplestep;
-			pos = sampleoffset;
+			float sampleoffset = startsample + ((x1_offset - x1) / stepsize + i) * samplestep;
+			p = sampleoffset;
 
-			value1 = waveform->data[pos * 3];
-			value2 = waveform->data[pos * 3 + 1];
+			value1 = waveform->data[p * 3];
+			value2 = waveform->data[p * 3 + 1];
 
 			if (samplestep > 1.0f) {
-				for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
+				for (j = p + 1; (j < waveform->length) && (j < p + samplestep); j++) {
 					if (value1 > waveform->data[j * 3])
 						value1 = waveform->data[j * 3];
 
@@ -266,34 +282,20 @@ static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequenc
 			}
 			else {
 				/* use simple linear interpolation */
-				float f = sampleoffset - pos;
-				value1 = (1.0f - f) * value1 + f * waveform->data[pos * 3 + 3];
-				value2 = (1.0f - f) * value2 + f * waveform->data[pos * 3 + 4];
+				float f = sampleoffset - p;
+				value1 = (1.0f - f) * value1 + f * waveform->data[p * 3 + 3];
+				value2 = (1.0f - f) * value2 + f * waveform->data[p * 3 + 4];
 			}
 
-			glVertex2f(x1 + i * stepsize, ymid + value1 * yscale);
-			glVertex2f(x1 + i * stepsize, ymid + value2 * yscale);
+			immVertex2f(pos, x1_offset + i * stepsize, ymid + value1 * yscale);
+			immVertex2f(pos, x1_offset + i * stepsize, ymid + value2 * yscale);
 		}
-		glEnd();
-		glDisable(GL_BLEND);
-	}
-}
 
-static void drawmeta_stipple(int value)
-{
-	if (value) {
-		GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
-		GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
-		
-		glEnable(GL_LINE_STIPPLE);
-		glLineStipple(1, 0x8888);
-	}
-	else {
-		GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-		glDisable(GL_LINE_STIPPLE);
+		immEnd();
+
+		glDisable(GL_BLEND);
 	}
 }
-
 static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float x2, float y2)
 {
 	/* note: this used to use SEQ_BEGIN/SEQ_END, but it messes up the
@@ -326,9 +328,6 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-	if (seqm->flag & SEQ_MUTE)
-		drawmeta_stipple(1);
-
 	for (seq = seqbase->first; seq; seq = seq->next) {
 		chan_min = min_ii(chan_min, seq->machine);
 		chan_max = max_ii(chan_max, seq->machine);
@@ -339,6 +338,10 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
 
 	col[3] = 196; /* alpha, used for all meta children */
 
+	unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
 	for (seq = seqbase->first; seq; seq = seq->next) {
 		const int startdisp = seq->startdisp + offset;
 		const int enddisp   = seq->enddisp   + offset;
@@ -349,12 +352,16 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
 			float x2_chan = enddisp;
 			float y1_chan, y2_chan;
 
-			if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
-				drawmeta_stipple(1);
-
 			color3ubv_from_seq(scene, seq, col);
 
-			glColor4ubv(col);
+			if ((seqm->flag & SEQ_MUTE) || (seq->flag & SEQ_MUTE)) {
+				col[3] = 64;
+			}
+			else {
+				col[3] = 196;
+			}
+
+			immUniformColor4ubv(col);
 			
 			/* clamp within parent sequence strip bounds */
 			if (x1_chan < x1) x1_chan = x1;
@@ -363,20 +370,12 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
 			y1_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSBOTTOM);
 			y2_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSTOP);
 
-			glRectf(x1_chan,  y1_chan, x2_chan,  y2_chan);
-
-			UI_GetColorPtrShade3ubv(col, col, -30);
-			glColor4ubv(col);
-			fdrawbox(x1_chan,  y1_chan, x2_chan,  y2_chan);
-
-			if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
-				drawmeta_stipple(0);
+			immRectf(pos, x1_chan,  y1_chan, x2_chan,  y2_chan);
 		}
 	}
 
-	if (seqm->flag & SEQ_MUTE)
-		drawmeta_stipple(0);
-	
+	immUnbindProgram();
+
 	glDisable(GL_BLEND);
 }
 
@@ -392,7 +391,7 @@ static float draw_seq_handle_size_get_clamped(Sequence *seq, const float pixelx)
 }
 
 /* draw a handle, for each end of a sequence strip */
-static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction)
+static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction, unsigned int pos)
 {
 	float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; //for triangles and rect
 	float x1, x2, y1, y2;
@@ -434,21 +433,31 @@ static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_cla
 		
 		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 		
-		if (seq->flag & whichsel) glColor4ub(0, 0, 0, 80);
-		else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30);
-		else glColor4ub(0, 0, 0, 22);
-		
-		glRectf(rx1, y1, rx2, y2);
-		
-		if (seq->flag & whichsel) glColor4ub(255, 255, 255, 200);
-		else glColor4ub(0, 0, 0, 50);
+		if (seq->flag & whichsel) {
+			immUniformColor4ub(0, 0, 0, 80);
+		}
+		else if (seq->flag & SELECT) {
+			immUniformColor4ub(255, 255, 255, 30);
+		}
+		else {
+			immUniformColor4ub(0, 0, 0, 22);
+		}
 		
-		glEnable(GL_POLYGON_SMOOTH);
-		glBegin(GL_TRIANGLES);
-		glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3);
-		glEnd();
+		immRectf(pos, rx1, y1, rx2, y2);
 		
-		glDisable(GL_POLYGON_SMOOTH);
+		if (seq->flag & whichsel) {
+			immUniformColor4ub(255, 255, 255, 200);
+		}
+		else {
+			immUniformColor4ub(0, 0, 0, 50);
+		}
+
+		immBegin(GL_TRIANGLES, 3);
+		immVertex2fv(pos, v1);
+		immVertex2fv(pos, v2);
+		immVertex2fv(pos, v3);
+		immEnd();
+
 		glDisable(GL_BLEND);
 	}
 	
@@ -586,67 +595,10 @@ static void draw_seq_text(View2D *v2d, SpaceSeq *sseq, Sequence *seq, float x1,
 	UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
 }
 
-/* draws a shaded strip, made from gradient + flat color + gradient */
-void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2)
+static void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq, unsigned int pos)
 {
-	float ymid1, ymid2;
-	
-	if (seq->flag & SEQ_MUTE) {
-		GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
-		GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
-	}
-	
-	ymid1 = (y2 - y1) * 0.25f + y1;
-	ymid2 = (y2 - y1) * 0.65f + y1;
-	
-	glBegin(GL_QUADS);
-	
-	if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
-	else if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
-	/* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
-	
-	glColor3ubv(col);
-	
-	glVertex2f(x1, y1);
-	glVertex2f(x2, y1);
-
-	if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
-	else if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 5);
-	else UI_GetColorPtrShade3ubv(col, col, -5);
-
-	glColor3ubv((GLubyte *)col);
-	
-	glVertex2f(x2, ymid1);
-	glVertex2f(x1, ymid1);
-	
-	glEnd();
-	
-	glRectf(x1,  ymid1,  x2,  ymid2);
-	
-	glBegin(GL_QUADS);
-	
-	glVertex2f(x1, ymid2);
-	glVertex2f(x2, ymid2);
-	
-	if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
-	else UI_GetColorPtrShade3ubv(col, col, 25);
-	
-	glColor3ubv((GLubyte *)col);
-	
-	glVertex2f(x2, y2);
-	glVertex2f(x1, y2);
-	
-	glEnd();
-	
-	if (seq->flag & SEQ_MUTE) {
-		GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-	}
-}
-
-static void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq)
-{
-	float x1, x2, y1, y2, pixely, a;
-	unsigned char col[3], blendcol[3];
+	float x1, x2, y1, y2, pixely;
+	unsigned char col[4], blendcol[3];
 	View2D

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list