Dynamic change of glshader element

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic change of glshader element

Christian Winkler

Dear Members,

 

i am trying to change a glshader element at runtime in a native Gstreamer application.

 

The idea is to convert a rtsp Stream to an side-by-side view for a android google cardboard VR device.

I want to implement headtracking as well and therefore want to change the opengl fragment dynamically based on head position.

 

The code below works for a static .frag file.

 

QUESTION: How can i change for example

const vec2 leftCenter = vec2(0.25, 0.4);

const vec2 rightCenter = vec2(0.75, 0.4);

DYNAMICALLY during runtime in the native code?

 

There used tob o something like gstglfiltershader, but i can not find a similar functionality in the current 1.4.x releases.

 

Thanks!!!!

Kind regards

Christian

 

 

The current Pipeline is set up as follows (JNI Code for an Android App).

This

 

 

                ….

                // rtspsrc location=rtsp://192.168.137.240:8554/test latency=0 drop-on-latency=true ! application/x-rtp, payload=96 ! rtph264depay ! decodebin ! glimagesink  sync=false

                data->source = gst_element_factory_make ("rtspsrc","rtspsrc");

                g_object_set(G_OBJECT (data->source),"location",pipelineParameterFromJava,"latency",0,"drop-on-latency",true,NULL);

 

                data->pipeline = gst_pipeline_new ("fpv-pipeline");

                data->filter=gst_element_factory_make("capsfilter","filter");

                data->depayloader  = gst_element_factory_make ("rtph264depay","rtph264depay");

                data->decoder  = gst_element_factory_make ("decodebin","decodebin");

                data->distortion = gst_element_factory_make ("glshader","glshader");

                data->video_sink = gst_element_factory_make ("glimagesink","glimagesink");

 

                filtercaps = gst_caps_new_simple ("application/x-rtp","payload", G_TYPE_INT, 96,NULL);

                g_object_set (G_OBJECT (data->filter), "caps", filtercaps, NULL);

                g_object_set (G_OBJECT (data->distortion), "location", "/data/data/com.lonestar.groundpi/files/distortion.frag", NULL);

                gst_caps_unref (filtercaps);

                g_object_set(G_OBJECT (data->video_sink),"sync",false,NULL);

 

                if (!data->pipeline || !data->source || !data->filter || !data->depayloader || !data->decoder || !data->video_sink || !data->distortion) {

                  g_printerr ("One element could not be created. Exiting.\n");

                  return -1;

                }

 

                gst_bin_add_many (GST_BIN (data->pipeline), data->source, data->filter, data->depayloader, data->decoder, data->video_sink, data->distortion, NULL);

                gst_element_link_many (data->filter, data->depayloader, data->decoder, NULL);

                gst_element_link_many (data->distortion, data->video_sink, NULL);

                g_signal_connect (data->source, "pad-added", G_CALLBACK (cb_new_pad), data->filter);

                g_signal_connect (data->decoder, "pad-added", G_CALLBACK (cb_new_pad), data->distortion);

….

 

 

 

 

Distortion.frag:

 

#extension GL_ARB_texture_rectangle : enable

precision mediump float;

varying vec2 v_texcoord;

uniform sampler2D tex;

const vec4 kappa = vec4(2.75,1.7,0.5,0.5);

const float screen_width = 1920.0;

const float screen_height = 1080.0;

const float scaleFactor = 0.62;

const vec2 leftCenter = vec2(0.25, 0.4);

const vec2 rightCenter = vec2(0.75, 0.4);

const float separation = -0.025;

const bool stereo_input = false;

 

// Scales input texture coordinates for distortion.

vec2 hmdWarp(vec2 LensCenter, vec2 texCoord, vec2 Scale, vec2 ScaleIn) {

vec2 theta = (texCoord - LensCenter) * ScaleIn;

float rSq = theta.x * theta.x + theta.y * theta.y;

vec2 rvector = theta * (kappa.x + kappa.y * rSq + kappa.z * rSq * rSq + kappa.w * rSq * rSq * rSq);

vec2 tc = LensCenter + Scale * rvector;

return tc;

}

bool validate(vec2 tc, int eye) {

if ( stereo_input ) {

//keep within bounds of texture

if ((eye == 1 && (tc.x < 0.0 || tc.x > 0.5)) ||

(eye == 0 && (tc.x < 0.5 || tc.x > 1.0)) ||

tc.y < 0.0 || tc.y > 1.0) {

return false;

}

} else {

if ( tc.x < 0.0 || tc.x > 1.0 ||

tc.y < 0.0 || tc.y > 1.0 ) {

return false;

}

}

return true;

}

void main() {

float as = float(screen_width / 2.0) / float(screen_height);

vec2 Scale = vec2(0.25, as);

vec2 ScaleIn = vec2(2.0 * scaleFactor, 1.0 / as * scaleFactor);

vec2 texCoord = v_texcoord;

vec2 tc = vec2(0);

vec4 color = vec4(0);

if ( texCoord.x < 0.5 ) {

texCoord.x += separation;

texCoord = hmdWarp(leftCenter, texCoord, Scale, ScaleIn );

if ( !stereo_input ) {

texCoord.x *= 2.0;

}

color = texture2D(tex, texCoord);

if ( !validate(texCoord, 0) ) {

color = vec4(0);

}

} else {

texCoord.x -= separation;

texCoord = hmdWarp(rightCenter, texCoord, Scale, ScaleIn);

if ( !stereo_input ) {

texCoord.x = (texCoord.x - 0.5) * 2.0;

}

color = texture2D(tex, texCoord);

if ( !validate(texCoord, 1) ) {

color = vec4(0);

}

}

gl_FragColor = color;

}

 

 

 

 


_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic change of glshader element

Dušan Poizl
change it to uniform variable. "uniform vec2 leftCenter;"

then you should be able to change it with gst_gl_shader_set_uniform_2f(shader, "leftCenter", x, y);

Dňa 15.11.2014 o 11:10 Christian Winkler napísal(a):

Dear Members,

 

i am trying to change a glshader element at runtime in a native Gstreamer application.

 

The idea is to convert a rtsp Stream to an side-by-side view for a android google cardboard VR device.

I want to implement headtracking as well and therefore want to change the opengl fragment dynamically based on head position.

 

The code below works for a static .frag file.

 

QUESTION: How can i change for example

const vec2 leftCenter = vec2(0.25, 0.4);

const vec2 rightCenter = vec2(0.75, 0.4);

DYNAMICALLY during runtime in the native code?

 

There used tob o something like gstglfiltershader, but i can not find a similar functionality in the current 1.4.x releases.

 

Thanks!!!!

Kind regards

Christian

 

 

The current Pipeline is set up as follows (JNI Code for an Android App).

This

 

 

                ….

                // rtspsrc location=<a class="moz-txt-link-freetext" href="rtsp://192.168.137.240:8554/test">rtsp://192.168.137.240:8554/test latency=0 drop-on-latency=true ! application/x-rtp, payload=96 ! rtph264depay ! decodebin ! glimagesink  sync=false

                data->source = gst_element_factory_make ("rtspsrc","rtspsrc");

                g_object_set(G_OBJECT (data->source),"location",pipelineParameterFromJava,"latency",0,"drop-on-latency",true,NULL);

 

                data->pipeline = gst_pipeline_new ("fpv-pipeline");

                data->filter=gst_element_factory_make("capsfilter","filter");

                data->depayloader  = gst_element_factory_make ("rtph264depay","rtph264depay");

                data->decoder  = gst_element_factory_make ("decodebin","decodebin");

                data->distortion = gst_element_factory_make ("glshader","glshader");

                data->video_sink = gst_element_factory_make ("glimagesink","glimagesink");

 

                filtercaps = gst_caps_new_simple ("application/x-rtp","payload", G_TYPE_INT, 96,NULL);

                g_object_set (G_OBJECT (data->filter), "caps", filtercaps, NULL);

                g_object_set (G_OBJECT (data->distortion), "location", "/data/data/com.lonestar.groundpi/files/distortion.frag", NULL);

                gst_caps_unref (filtercaps);

                g_object_set(G_OBJECT (data->video_sink),"sync",false,NULL);

 

                if (!data->pipeline || !data->source || !data->filter || !data->depayloader || !data->decoder || !data->video_sink || !data->distortion) {

                  g_printerr ("One element could not be created. Exiting.\n");

                  return -1;

                }

 

                gst_bin_add_many (GST_BIN (data->pipeline), data->source, data->filter, data->depayloader, data->decoder, data->video_sink, data->distortion, NULL);

                gst_element_link_many (data->filter, data->depayloader, data->decoder, NULL);

                gst_element_link_many (data->distortion, data->video_sink, NULL);

                g_signal_connect (data->source, "pad-added", G_CALLBACK (cb_new_pad), data->filter);

                g_signal_connect (data->decoder, "pad-added", G_CALLBACK (cb_new_pad), data->distortion);

….

 

 

 

 

Distortion.frag:

 

#extension GL_ARB_texture_rectangle : enable

precision mediump float;

varying vec2 v_texcoord;

uniform sampler2D tex;

const vec4 kappa = vec4(2.75,1.7,0.5,0.5);

const float screen_width = 1920.0;

const float screen_height = 1080.0;

const float scaleFactor = 0.62;

const vec2 leftCenter = vec2(0.25, 0.4);

const vec2 rightCenter = vec2(0.75, 0.4);

const float separation = -0.025;

const bool stereo_input = false;

 

// Scales input texture coordinates for distortion.

vec2 hmdWarp(vec2 LensCenter, vec2 texCoord, vec2 Scale, vec2 ScaleIn) {

vec2 theta = (texCoord - LensCenter) * ScaleIn;

float rSq = theta.x * theta.x + theta.y * theta.y;

vec2 rvector = theta * (kappa.x + kappa.y * rSq + kappa.z * rSq * rSq + kappa.w * rSq * rSq * rSq);

vec2 tc = LensCenter + Scale * rvector;

return tc;

}

bool validate(vec2 tc, int eye) {

if ( stereo_input ) {

//keep within bounds of texture

if ((eye == 1 && (tc.x < 0.0 || tc.x > 0.5)) ||

(eye == 0 && (tc.x < 0.5 || tc.x > 1.0)) ||

tc.y < 0.0 || tc.y > 1.0) {

return false;

}

} else {

if ( tc.x < 0.0 || tc.x > 1.0 ||

tc.y < 0.0 || tc.y > 1.0 ) {

return false;

}

}

return true;

}

void main() {

float as = float(screen_width / 2.0) / float(screen_height);

vec2 Scale = vec2(0.25, as);

vec2 ScaleIn = vec2(2.0 * scaleFactor, 1.0 / as * scaleFactor);

vec2 texCoord = v_texcoord;

vec2 tc = vec2(0);

vec4 color = vec4(0);

if ( texCoord.x < 0.5 ) {

texCoord.x += separation;

texCoord = hmdWarp(leftCenter, texCoord, Scale, ScaleIn );

if ( !stereo_input ) {

texCoord.x *= 2.0;

}

color = texture2D(tex, texCoord);

if ( !validate(texCoord, 0) ) {

color = vec4(0);

}

} else {

texCoord.x -= separation;

texCoord = hmdWarp(rightCenter, texCoord, Scale, ScaleIn);

if ( !stereo_input ) {

texCoord.x = (texCoord.x - 0.5) * 2.0;

}

color = texture2D(tex, texCoord);

if ( !validate(texCoord, 1) ) {

color = vec4(0);

}

}

gl_FragColor = color;

}

 

 

 

 



_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic change of glshader element

luc.deschenaux
In reply to this post by Christian Winkler
You could also initialize the uniform variables using text values (using GLSL syntax) with something like
        g_object_set (G_OBJECT (glshader), "preset", str, NULL)

or change their value using text values with
        g_object_set (G_OBJECT (glshader), "vars", str, NULL)

See https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id=146619

But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.
Reply | Threaded
Open this post in threaded view
|

AW: Dynamic change of glshader element

Christian Winkler
Dear Luc,

thanks.
I definitley have trouble setting the presets.
Either by command line or code, they are not accepted.

For instance:
gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width=1280, height=720" ! videoconvert ! glshader location=dist.frag preset=dist.preset ! glimagesink


dist frag:
precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

const vec4 kappa = vec4(2.75,1.7,0.5,0.5);
const float screen_width = 1920.0;
const float screen_height = 1080.0;
const vec2 leftCenter = vec2(0.25, 0.4);
const vec2 rightCenter = vec2(0.75, 0.4);
const float separation = -0.025;
const bool stereo_input = false;
uniform float scaleFactor;
.........

dist.preset:
float scaleFactor = float(0.2);

or, also tried:
float scaleFactor = 0.2;


The value 0.2 is simply ignored.
I dont know why that happens

scaleFactor iss et to 0.

-----Ursprüngliche Nachricht-----
Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von luc.deschenaux
Gesendet: Montag, 17. November 2014 04:45
An: [hidden email]
Betreff: Re: Dynamic change of glshader element

You could also initialize the uniform variables using text values (using GLSL
syntax) with something like
        g_object_set (G_OBJECT (glshader), "preset", str, NULL)

or change their value using text values with
        g_object_set (G_OBJECT (glshader), "vars", str, NULL)

See
https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id=146619

But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshader-element-tp4669514p4669526.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: AW: Dynamic change of glshader element

Luc Deschenaux

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Required syntax is eg "float f=float(0.0);"

Maybe there's a problem with the text file encoding or line ending ?..

Sorry I cannot help a lot right now i'm quite busy, I have no time to
build the latest gstreamer and try to figure out what's happening with a
debugger

There's a script and instructions about how to build gstreamer on this
page (need to add gst-plugins-gl to the list):
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/faq/html/chapter-developing.html#developing-uninstalled-gstreamer

You should look for "preset" in
gstglfiltershader.c

or check whether "gst_gl_shader_set_uniform_1f" is reached in
gstglshadervariables.c and is feed with the right value.

Regards,

Luc

On 19. 11. 14 04:18, Christian Winkler wrote:
> Dear Luc,
>
> thanks.
> I definitley have trouble setting the presets.
> Either by command line or code, they are not accepted.
>
> For instance:
> gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width=1280,
height=720" ! videoconvert ! glshader location=dist.frag
preset=dist.preset ! glimagesink

>
>
> dist frag:
> precision mediump float;
> varying vec2 v_texcoord;
> uniform sampler2D tex;
>
> const vec4 kappa = vec4(2.75,1.7,0.5,0.5);
> const float screen_width = 1920.0;
> const float screen_height = 1080.0;
> const vec2 leftCenter = vec2(0.25, 0.4);
> const vec2 rightCenter = vec2(0.75, 0.4);
> const float separation = -0.025;
> const bool stereo_input = false;
> uniform float scaleFactor;
> .........
>
> dist.preset:
> float scaleFactor = float(0.2);
>
> or, also tried:
> float scaleFactor = 0.2;
>
>
> The value 0.2 is simply ignored.
> I dont know why that happens
>
> scaleFactor iss et to 0.
>
> -----Ursprüngliche Nachricht-----
> Von: gstreamer-devel
[mailto:[hidden email]] Im Auftrag von
luc.deschenaux
> Gesendet: Montag, 17. November 2014 04:45
> An: [hidden email]
> Betreff: Re: Dynamic change of glshader element
>
> You could also initialize the uniform variables using text values
(using GLSL

> syntax) with something like
>         g_object_set (G_OBJECT (glshader), "preset", str, NULL)
>
> or change their value using text values with
>         g_object_set (G_OBJECT (glshader), "vars", str, NULL)
>
> See
> https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id=146619
>
> But since this rely on the gst_gl_shader_set_uniform methods (with the
overhead implied for parsing the text string), calling the
gst_gl_shader_set_uniforms methods directly is more efficient for
modifying values dynamically.
>
>
>
> --
> View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshader-element-tp4669514p4669526.html

> Sent from the GStreamer-devel mailing list archive at Nabble.com.
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


- --
Luc Deschenaux

t: 0788 266 366
v: 0225 085 085 @ netvoip.ch
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJUbChXAAoJEK8C+AaU4Dv9xtwQAIJP4hiDEfvuOoicYlovi0RR
tpldzEIEcRRyr0O+GM4kbyZ1PIGxjnvREuf0qxhUXSjc7gdQFJvj+ZudunbzTvKu
+GR7n9+BQDRxgsf0poQJitFMsmpnNc0HCH36JVcfp3tr7HEwsQ+H9Ds94rs94Pg+
BD0U7WpBXDZVhmKdox5EfhdGNyhmUfzUN95CcJsNPxQlpa+vf2SanQEJOHlM3Mlz
dC68FCDG2bABl554bJKh765ULmFpbiTCHaVvZi6zUeQktW9eHBRBVP22wgOHaaYc
otZAAnFmjOI97rBp4WibUIQbYBBnKiJlVNdbM0+gycBxoByeWjCpyU1ExvfRHlBs
AoW70lcUe6laETOlUQckbClXngq+a0sx1+j9sDgYcOWQayFTWfIScU/Hbie4BMxf
qJe863IOc8IrY5yq8czouv/Kkzm2zCSsAhmiysYgcPST5ktn6vpVY896XoI7G+FV
G/M67zQBxuMDfkCd4U/TeuiM7dtoJyNCyOl6i1VWkdpvJ6mTH3n5W3Aj58yoJk9+
1/Rqa//CM7MPD662mba60YLYIZsJAoir0MXkxYJk2m/VBH/45kb7kNhY1d2NqHvE
FMZRVRufj0QVxSDD4fBKZcJMRbvOj7vhVYIPZktSLvtyOuGBCqWKnxxNpSxIyYWj
UNpO4CTe+vu2D+bs0j3V
=B4IK
-----END PGP SIGNATURE-----


_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: AW: Dynamic change of glshader element

Matthew Waters
In reply to this post by Christian Winkler
On 19/11/14 08:18, Christian Winkler wrote:

> Dear Luc,
>
> thanks.
> I definitley have trouble setting the presets.
> Either by command line or code, they are not accepted.
>
> For instance:
> gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width80, heightr0" ! videoconvert ! glshader location=dist.frag preset=dist.preset ! glimagesink
>
>
> dist frag:
> precision mediump float;
> varying vec2 v_texcoord;
> uniform sampler2D tex;
>
> const vec4 kappa =ec4(2.75,1.7,0.5,0.5);
> const float screen_width =920.0;
> const float screen_height =080.0;
> const vec2 leftCenter =ec2(0.25, 0.4);
> const vec2 rightCenter =ec2(0.75, 0.4);
> const float separation =0.025;
> const bool stereo_input =alse;
> uniform float scaleFactor;
> .........
>
> dist.preset:
> float scaleFactor = float(0.2);
>
> or, also tried:
> float scaleFactor =.2;
The following works for me.  Note that you need the float on both sides
of the assignment in the preset and they must be the same type.  Also,
you could try running with the gst debug log and seeing what it outputs.

preset/vars:
float scale = float(0.2);

shader:
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texcoord;
uniform sampler2D tex;
uniform float scale;

void main () {
  gl_FragColor = texture2D( tex, v_texcoord ) * vec4(vec3(scale), 1.0);
}

> The value 0.2 is simply ignored.
> I dont know why that happens
>
> scaleFactor iss et to 0.
>
> -----Ursprüngliche Nachricht-----
> Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von luc.deschenaux
> Gesendet: Montag, 17. November 2014 04:45
> An: [hidden email]
> Betreff: Re: Dynamic change of glshader element
>
> You could also initialize the uniform variables using text values (using GLSL
> syntax) with something like
>         g_object_set (G_OBJECT (glshader), "preset", str, NULL)
>
> or change their value using text values with
>         g_object_set (G_OBJECT (glshader), "vars", str, NULL)
>
> See
> <a href="https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id6619">https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id6619
>
> But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.
>
>
>
> --
> View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshader-element-tp4669514p4669526.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
>


_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

AW: AW: Dynamic change of glshader element

Christian Winkler
Ok...after hours of trying to get uniforms working even in command line i have to come to a simple conclusion:
The setting of a preset file for a glshader element is broken in the windows version of gstreamer.
It works under android and ubuntu....

What a waste of time :-/

Thanks to all of you for your help.

Now lets go fort he c code...

-----Ursprüngliche Nachricht-----
Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Matthew Waters
Gesendet: Mittwoch, 19. November 2014 10:45
An: [hidden email]
Betreff: Re: AW: Dynamic change of glshader element

On 19/11/14 08:18, Christian Winkler wrote:

> Dear Luc,
>
> thanks.
> I definitley have trouble setting the presets.
> Either by command line or code, they are not accepted.
>
> For instance:
> gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width80,
> heightr0" ! videoconvert ! glshader location=dist.frag
> preset=dist.preset ! glimagesink
>
>
> dist frag:
> precision mediump float;
> varying vec2 v_texcoord;
> uniform sampler2D tex;
>
> const vec4 kappa =ec4(2.75,1.7,0.5,0.5); const float screen_width
> =920.0; const float screen_height =080.0; const vec2 leftCenter
> =ec2(0.25, 0.4); const vec2 rightCenter =ec2(0.75, 0.4); const float
> separation =0.025; const bool stereo_input =alse; uniform float
> scaleFactor; .........
>
> dist.preset:
> float scaleFactor = float(0.2);
>
> or, also tried:
> float scaleFactor =.2;

The following works for me.  Note that you need the float on both sides of the assignment in the preset and they must be the same type.  Also, you could try running with the gst debug log and seeing what it outputs.

preset/vars:
float scale = float(0.2);

shader:
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texcoord;
uniform sampler2D tex;
uniform float scale;

void main () {
  gl_FragColor = texture2D( tex, v_texcoord ) * vec4(vec3(scale), 1.0); }

> The value 0.2 is simply ignored.
> I dont know why that happens
>
> scaleFactor iss et to 0.
>
> -----Ursprüngliche Nachricht-----
> Von: gstreamer-devel
> [mailto:[hidden email]] Im Auftrag von
> luc.deschenaux
> Gesendet: Montag, 17. November 2014 04:45
> An: [hidden email]
> Betreff: Re: Dynamic change of glshader element
>
> You could also initialize the uniform variables using text values
> (using GLSL
> syntax) with something like
>         g_object_set (G_OBJECT (glshader), "preset", str, NULL)
>
> or change their value using text values with
>         g_object_set (G_OBJECT (glshader), "vars", str, NULL)
>
> See
> <a href="https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id661">https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id661
> 9
>
> But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.
>
>
>
> --
> View this message in context:
> http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshader
> -element-tp4669514p4669526.html Sent from the GStreamer-devel mailing
> list archive at Nabble.com.
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
>



_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

AW: AW: Dynamic change of glshader element

Christian Winkler
So, now i have a small proof of concept, which allows change of uniforms variables.
But this is obviously file based, not fast enough, and worst of all, requires the pipeline tob e stopped for changing uniforms


typedef struct _CustomData {
  GstElement *pipeline;   /* The running pipeline */
  GstElement *distortion;   /* The glshader element */
...
} CustomData;

void gst_native_set_shiftxy (JNIEnv* env, jobject thiz, jfloat shiftx, jfloat shifty) {
        CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
        gst_element_set_state (data->pipeline, GST_STATE_READY);
        g_object_set (G_OBJECT (data->distortion), "preset", "/data/data/com.lonestar.groundpi/files/dist.mod", NULL);
         gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
}

Actually, i want to have something like this: No interruption of running pipe, but on the fly change of shader.
After reading of tons of sites ant source code, i still dont get it.
Any help out there?

void gst_native_set_shiftxy (JNIEnv* env, jobject thiz, jfloat shiftx, jfloat shifty) {
        CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);

.. ???

        gst_gl_shader_set_uniform_1f(G_OBJECT ( data->distortion ) , "shiftX", shiftx); // Gives an exception violation
        gst_gl_shader_set_uniform_1f(G_OBJECT ( data->distortion ) , "shiftY", shifty);

-- ???
}



-----Ursprüngliche Nachricht-----
Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Christian Winkler
Gesendet: Sonntag, 23. November 2014 13:05
An: 'Discussion of the development of and with GStreamer'
Betreff: AW: AW: Dynamic change of glshader element

Ok...after hours of trying to get uniforms working even in command line i have to come to a simple conclusion:
The setting of a preset file for a glshader element is broken in the windows version of gstreamer.
It works under android and ubuntu....

What a waste of time :-/

Thanks to all of you for your help.

Now lets go fort he c code...

-----Ursprüngliche Nachricht-----
Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Matthew Waters
Gesendet: Mittwoch, 19. November 2014 10:45
An: [hidden email]
Betreff: Re: AW: Dynamic change of glshader element

On 19/11/14 08:18, Christian Winkler wrote:

> Dear Luc,
>
> thanks.
> I definitley have trouble setting the presets.
> Either by command line or code, they are not accepted.
>
> For instance:
> gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width80,
> heightr0" ! videoconvert ! glshader location=dist.frag
> preset=dist.preset ! glimagesink
>
>
> dist frag:
> precision mediump float;
> varying vec2 v_texcoord;
> uniform sampler2D tex;
>
> const vec4 kappa =ec4(2.75,1.7,0.5,0.5); const float screen_width
> =920.0; const float screen_height =080.0; const vec2 leftCenter
> =ec2(0.25, 0.4); const vec2 rightCenter =ec2(0.75, 0.4); const float
> separation =0.025; const bool stereo_input =alse; uniform float
> scaleFactor; .........
>
> dist.preset:
> float scaleFactor = float(0.2);
>
> or, also tried:
> float scaleFactor =.2;

The following works for me.  Note that you need the float on both sides of the assignment in the preset and they must be the same type.  Also, you could try running with the gst debug log and seeing what it outputs.

preset/vars:
float scale = float(0.2);

shader:
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texcoord;
uniform sampler2D tex;
uniform float scale;

void main () {
  gl_FragColor = texture2D( tex, v_texcoord ) * vec4(vec3(scale), 1.0); }

> The value 0.2 is simply ignored.
> I dont know why that happens
>
> scaleFactor iss et to 0.
>
> -----Ursprüngliche Nachricht-----
> Von: gstreamer-devel
> [mailto:[hidden email]] Im Auftrag von
> luc.deschenaux
> Gesendet: Montag, 17. November 2014 04:45
> An: [hidden email]
> Betreff: Re: Dynamic change of glshader element
>
> You could also initialize the uniform variables using text values
> (using GLSL
> syntax) with something like
>         g_object_set (G_OBJECT (glshader), "preset", str, NULL)
>
> or change their value using text values with
>         g_object_set (G_OBJECT (glshader), "vars", str, NULL)
>
> See
> <a href="https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id661">https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id661
> 9
>
> But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.
>
>
>
> --
> View this message in context:
> http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshader
> -element-tp4669514p4669526.html Sent from the GStreamer-devel mailing
> list archive at Nabble.com.
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
>



_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Dynamic change of glshader element

Matthew Waters
In reply to this post by Christian Winkler
On 23/11/14 23:04, Christian Winkler wrote:
> Ok...after hours of trying to get uniforms working even in command line i have to come to a simple conclusion:
> The setting of a preset file for a glshader element is broken in the windows version of gstreamer.
> It works under android and ubuntu....
>
> What a waste of time :-/

This could possibly be a line endings issue.  What happens if you take
the preset file from ubuntu/android and use it in a windows
environment?  If it is, the following should fix your issue.

http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=59085936b820e02734097c17d6dfeb2387f22d9f

Otherwise please open a bug against gst-plugins-bad here
https://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer
It would be most helpful if you could also attach a
GST_DEBUG=default:7,gl*:7 log to the bug.

> Thanks to all of you for your help.
>
> Now lets go fort he c code...
>
> -----Ursprüngliche Nachricht-----
> Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Matthew Waters
> Gesendet: Mittwoch, 19. November 2014 10:45
> An: [hidden email]
> Betreff: Re: AW: Dynamic change of glshader element
>
> On 19/11/14 08:18, Christian Winkler wrote:
>> Dear Luc,
>>
>> thanks.
>> I definitley have trouble setting the presets.
>> Either by command line or code, they are not accepted.
>>
>> For instance:
>> gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width80,
>> heightr0" ! videoconvert ! glshader location=st.frag
>> preset=st.preset ! glimagesink
>>
>>
>> dist frag:
>> precision mediump float;
>> varying vec2 v_texcoord;
>> uniform sampler2D tex;
>>
>> const vec4 kappa �4(2.75,1.7,0.5,0.5); const float screen_width
>> �0.0; const float screen_height 0.0; const vec2 leftCenter
>> �2(0.25, 0.4); const vec2 rightCenter �2(0.75, 0.4); const float
>> separation =025; const bool stereo_input =alse; uniform float
>> scaleFactor; .........
>>
>> dist.preset:
>> float scaleFactor =loat(0.2);
>>
>> or, also tried:
>> float scaleFactor =;
> The following works for me.  Note that you need the float on both sides of the assignment in the preset and they must be the same type.  Also, you could try running with the gst debug log and seeing what it outputs.
>
> preset/vars:
> float scale =loat(0.2);
>
> shader:
> #ifdef GL_ES
> precision mediump float;
> #endif
> varying vec2 v_texcoord;
> uniform sampler2D tex;
> uniform float scale;
>
> void main () {
>   gl_FragColor =exture2D( tex, v_texcoord ) * vec4(vec3(scale), 1.0); }
>
>> The value 0.2 is simply ignored.
>> I dont know why that happens
>>
>> scaleFactor iss et to 0.
>>
>> -----Ursprüngliche Nachricht-----
>> Von: gstreamer-devel
>> [mailto:[hidden email]] Im Auftrag von
>> luc.deschenaux
>> Gesendet: Montag, 17. November 2014 04:45
>> An: [hidden email]
>> Betreff: Re: Dynamic change of glshader element
>>
>> You could also initialize the uniform variables using text values
>> (using GLSL
>> syntax) with something like
>>         g_object_set (G_OBJECT (glshader), "preset", str, NULL)
>>
>> or change their value using text values with
>>         g_object_set (G_OBJECT (glshader), "vars", str, NULL)
>>
>> See
>> <a href="https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id661">https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id661
>> 9
>>
>> But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.
>>
>>
>>
>> --
>> View this message in context:
>> http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshader
>> -element-tp4669514p4669526.html Sent from the GStreamer-devel mailing
>> list archive at Nabble.com.
>> _______________________________________________
>> gstreamer-devel mailing list
>> [hidden email]
>> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>>
>>
>
>
>


_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

AW: AW: AW: Dynamic change of glshader element

Christian Winkler
I dont see that it is a line ending issue, i tried all possible combinations.

Part oft he log (Position 21 is the opening bracket...):
....

0:00:09.974702317  7576 00000000029D7540 INFO                 default gstglshadervariables.c:233:gst_gl_shadervariables_parse: vartype : 'float'

0:00:09.977922208  7576 00000000029D7540 INFO                 default gstglshadervariables.c:246:gst_gl_shadervariables_parse: varname : 'shiftX'

0:00:09.980697623  7576 00000000029D7540 INFO                 default gstglshadervariables.c:247:gst_gl_shadervariables_parse: arraysize : 0

0:00:09.983411459  7576 00000000029D7540 ERROR                default gstglshadervariables.c:322:gst_gl_shadervariables_parse:
float shiftX = float(0.1);
0:00:09.986446612  7576 00000000029D7540 ERROR                default gstglshadervariables.c:326:gst_gl_shadervariables_parse: parse error on line 1, position 21 (0.1))
0:00:09.989962164  7576 00000000029D7540 TRACE               glwindow gstglwindow_win32.c:309:gst_gl_window_win32_run: handle message



-----Ursprüngliche Nachricht-----
Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Matthew Waters
Gesendet: Sonntag, 23. November 2014 16:59
An: [hidden email]
Betreff: Re: AW: AW: Dynamic change of glshader element

On 23/11/14 23:04, Christian Winkler wrote:
> Ok...after hours of trying to get uniforms working even in command line i have to come to a simple conclusion:
> The setting of a preset file for a glshader element is broken in the windows version of gstreamer.
> It works under android and ubuntu....
>
> What a waste of time :-/

This could possibly be a line endings issue.  What happens if you take the preset file from ubuntu/android and use it in a windows environment?  If it is, the following should fix your issue.

http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=59085936b820e02734097c17d6dfeb2387f22d9f

Otherwise please open a bug against gst-plugins-bad here https://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer
It would be most helpful if you could also attach a
GST_DEBUG=default:7,gl*:7 log to the bug.

> Thanks to all of you for your help.
>
> Now lets go fort he c code...
>
> -----Ursprüngliche Nachricht-----
> Von: gstreamer-devel
> [mailto:[hidden email]] Im Auftrag von
> Matthew Waters
> Gesendet: Mittwoch, 19. November 2014 10:45
> An: [hidden email]
> Betreff: Re: AW: Dynamic change of glshader element
>
> On 19/11/14 08:18, Christian Winkler wrote:
>> Dear Luc,
>>
>> thanks.
>> I definitley have trouble setting the presets.
>> Either by command line or code, they are not accepted.
>>
>> For instance:
>> gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width80,
>> heightr0" ! videoconvert ! glshader location=st.frag preset=st.preset
>> ! glimagesink
>>
>>
>> dist frag:
>> precision mediump float;
>> varying vec2 v_texcoord;
>> uniform sampler2D tex;
>>
>> const vec4 kappa  4(2.75,1.7,0.5,0.5); const float screen_width  0.0;
>> const float screen_height 0.0; const vec2 leftCenter  2(0.25, 0.4);
>> const vec2 rightCenter  2(0.75, 0.4); const float separation =025;
>> const bool stereo_input =alse; uniform float scaleFactor; .........
>>
>> dist.preset:
>> float scaleFactor =loat(0.2);
>>
>> or, also tried:
>> float scaleFactor =;
> The following works for me.  Note that you need the float on both sides of the assignment in the preset and they must be the same type.  Also, you could try running with the gst debug log and seeing what it outputs.
>
> preset/vars:
> float scale =loat(0.2);
>
> shader:
> #ifdef GL_ES
> precision mediump float;
> #endif
> varying vec2 v_texcoord;
> uniform sampler2D tex;
> uniform float scale;
>
> void main () {
>   gl_FragColor =exture2D( tex, v_texcoord ) * vec4(vec3(scale), 1.0);
> }
>
>> The value 0.2 is simply ignored.
>> I dont know why that happens
>>
>> scaleFactor iss et to 0.
>>
>> -----Ursprüngliche Nachricht-----
>> Von: gstreamer-devel
>> [mailto:[hidden email]] Im Auftrag von
>> luc.deschenaux
>> Gesendet: Montag, 17. November 2014 04:45
>> An: [hidden email]
>> Betreff: Re: Dynamic change of glshader element
>>
>> You could also initialize the uniform variables using text values
>> (using GLSL
>> syntax) with something like
>>         g_object_set (G_OBJECT (glshader), "preset", str, NULL)
>>
>> or change their value using text values with
>>         g_object_set (G_OBJECT (glshader), "vars", str, NULL)
>>
>> See
>> <a href="https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id66">https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id66
>> 1
>> 9
>>
>> But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.
>>
>>
>>
>> --
>> View this message in context:
>> http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshade
>> r -element-tp4669514p4669526.html Sent from the GStreamer-devel
>> mailing list archive at Nabble.com.
>> _______________________________________________
>> gstreamer-devel mailing list
>> [hidden email]
>> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>>
>>
>
>
>



_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: AW: Dynamic change of glshader element

Tim Müller
On Sun, 2014-11-23 at 21:10 +0100, Christian Winkler wrote:

Hi,

I wonder if it might be a locale issue with the floating point
variables.

Are you using a German locale? If yes, the system (strtod) expects
floating point numbers to be like 1/2 = 0,5 for Germany and not 0.5. You
can try the attached patch to see if it makes a difference.

But then, I would expect strtod to just return 0 in this case and stop
parsing at the comma, and the code doesn't check for parsing errors, so
perhaps it's something else after all.

 Cheers
  -Tim

> I dont see that it is a line ending issue, i tried all possible combinations.
>
> Part oft he log (Position 21 is the opening bracket...):
> ....
>
> 0:00:09.974702317  7576 00000000029D7540 INFO                 default gstglshadervariables.c:233:gst_gl_shadervariables_parse: vartype : 'float'
>
> 0:00:09.977922208  7576 00000000029D7540 INFO                 default gstglshadervariables.c:246:gst_gl_shadervariables_parse: varname : 'shiftX'
>
> 0:00:09.980697623  7576 00000000029D7540 INFO                 default gstglshadervariables.c:247:gst_gl_shadervariables_parse: arraysize : 0
>
> 0:00:09.983411459  7576 00000000029D7540 ERROR                default gstglshadervariables.c:322:gst_gl_shadervariables_parse:
> float shiftX = float(0.1);
> 0:00:09.986446612  7576 00000000029D7540 ERROR                default gstglshadervariables.c:326:gst_gl_shadervariables_parse: parse error on line 1, position 21 (0.1))
> 0:00:09.989962164  7576 00000000029D7540 TRACE               glwindow gstglwindow_win32.c:309:gst_gl_window_win32_run: handle message
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Matthew Waters
> Gesendet: Sonntag, 23. November 2014 16:59
> An: [hidden email]
> Betreff: Re: AW: AW: Dynamic change of glshader element
>
> On 23/11/14 23:04, Christian Winkler wrote:
> > Ok...after hours of trying to get uniforms working even in command line i have to come to a simple conclusion:
> > The setting of a preset file for a glshader element is broken in the windows version of gstreamer.
> > It works under android and ubuntu....
> >
> > What a waste of time :-/
>
> This could possibly be a line endings issue.  What happens if you take the preset file from ubuntu/android and use it in a windows environment?  If it is, the following should fix your issue.
>
> http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=59085936b820e02734097c17d6dfeb2387f22d9f
>
> Otherwise please open a bug against gst-plugins-bad here https://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer
> It would be most helpful if you could also attach a
> GST_DEBUG=default:7,gl*:7 log to the bug.
>
> > Thanks to all of you for your help.
> >
> > Now lets go fort he c code...
> >
> > -----Ursprüngliche Nachricht-----
> > Von: gstreamer-devel
> > [mailto:[hidden email]] Im Auftrag von
> > Matthew Waters
> > Gesendet: Mittwoch, 19. November 2014 10:45
> > An: [hidden email]
> > Betreff: Re: AW: Dynamic change of glshader element
> >
> > On 19/11/14 08:18, Christian Winkler wrote:
> >> Dear Luc,
> >>
> >> thanks.
> >> I definitley have trouble setting the presets.
> >> Either by command line or code, they are not accepted.
> >>
> >> For instance:
> >> gst-launch-1.0.exe -e -v videotestsrc ! "video/x-raw, width80,
> >> heightr0" ! videoconvert ! glshader location=st.frag preset=st.preset
> >> ! glimagesink
> >>
> >>
> >> dist frag:
> >> precision mediump float;
> >> varying vec2 v_texcoord;
> >> uniform sampler2D tex;
> >>
> >> const vec4 kappa  4(2.75,1.7,0.5,0.5); const float screen_width  0.0;
> >> const float screen_height 0.0; const vec2 leftCenter  2(0.25, 0.4);
> >> const vec2 rightCenter  2(0.75, 0.4); const float separation =025;
> >> const bool stereo_input =alse; uniform float scaleFactor; .........
> >>
> >> dist.preset:
> >> float scaleFactor =loat(0.2);
> >>
> >> or, also tried:
> >> float scaleFactor =;
> > The following works for me.  Note that you need the float on both sides of the assignment in the preset and they must be the same type.  Also, you could try running with the gst debug log and seeing what it outputs.
> >
> > preset/vars:
> > float scale =loat(0.2);
> >
> > shader:
> > #ifdef GL_ES
> > precision mediump float;
> > #endif
> > varying vec2 v_texcoord;
> > uniform sampler2D tex;
> > uniform float scale;
> >
> > void main () {
> >   gl_FragColor =exture2D( tex, v_texcoord ) * vec4(vec3(scale), 1.0);
> > }
> >
> >> The value 0.2 is simply ignored.
> >> I dont know why that happens
> >>
> >> scaleFactor iss et to 0.
> >>
> >> -----Ursprüngliche Nachricht-----
> >> Von: gstreamer-devel
> >> [mailto:[hidden email]] Im Auftrag von
> >> luc.deschenaux
> >> Gesendet: Montag, 17. November 2014 04:45
> >> An: [hidden email]
> >> Betreff: Re: Dynamic change of glshader element
> >>
> >> You could also initialize the uniform variables using text values
> >> (using GLSL
> >> syntax) with something like
> >>         g_object_set (G_OBJECT (glshader), "preset", str, NULL)
> >>
> >> or change their value using text values with
> >>         g_object_set (G_OBJECT (glshader), "vars", str, NULL)
> >>
> >> See
> >> <a href="https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id66">https://bug600195.bugzilla-attachments.gnome.org/attachment.cgi?id66
> >> 1
> >> 9
> >>
> >> But since this rely on the gst_gl_shader_set_uniform methods (with the overhead implied for parsing the text string), calling the gst_gl_shader_set_uniforms methods directly is more efficient for modifying values dynamically.
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >> http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshade
> >> r -element-tp4669514p4669526.html Sent from the GStreamer-devel
> >> mailing list archive at Nabble.com.
> >> _______________________________________________
> >> gstreamer-devel mailing list
> >> [hidden email]
> >> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
> >>
> >>
> >
> >
> >
>
>
>
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
--
Tim Müller, Centricular Ltd - http://www.centricular.com

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

0001-gl-shadervariables-make-parsing-of-floats-locale-ind.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: AW: Dynamic change of glshader element

pfarmer
In reply to this post by Christian Winkler
Hi,

i ran into the same problem. I have GStreamer 1.6.1 on windows and i tried to get a uniform variable value into the shader. The error must come somewhere here (from http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/gst-libs/gst/gl/gstglshadervariables.c?h=1.6.1 )

      // extract variable value
      t = strtok_r (0, ";", &saveptr);
      if (!t)
        goto parse_error;
      trimleft (t, " \t");
      trimright (t, " \t");

      if (!t[0])
        goto parse_error;
      if (*(saveptr - 2) != ')')
        goto parse_error;
      *(saveptr - 2) = 0;
      if (!t[0])
        goto parse_error;

      varvalue = g_strdup (t);
      GST_INFO ("value: %s\n\n", varvalue);


The GST_INFO with "value" is never reached. I only get:

INFO                 default gstglshadervariables.c:233:gst_gl_shadervariables_parse: vartype : 'float'

INFO                 default gstglshadervariables.c:246:gst_gl_shadervariables_parse: varname : 'f'

INFO                 default gstglshadervariables.c:247:gst_gl_shadervariables_parse: arraysize : 0

ERROR                default gstglshadervariables.c:322:gst_gl_shadervariables_parse:

ERROR                default gstglshadervariables.c:326:gst_gl_shadervariables_parse: parse error on line 1, position 14 (1.0))

Did you meanwhile found a solution for this?

I tried to use

gst_gl_shader_set_uniform_1f(GST_GL_SHADER(shader), "f", 1.0f);

from the code. But I failed to get the GstGLShader from the glshader GstElement from the pipeline

GLib-GObject-WARNING **: invalid cast from 'GstGLFilterShader' to 'GstGLShader'

Any Idea how i could get the GstGLShader ?

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic change of glshader element

Holger
In reply to this post by Dušan Poizl
Hi,

I use python to build the pipeline. How can I change the uniform variables within the python code?
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic change of glshader element

Holger
Hi,

I don't want to spam the mailing list, but I don't find any good documentation for gst and python.

After adding:
gi.require_version('GstGL', '1.0')
from gi.repository import GstGL

I can get a reference to the shader element by:
sh = el_glshader.get_property("shader")

But if I change a value with....
sh.set_uniform_1f("separation", -0.01)

the application crashes. The behavior also doesn't change if I try to set a variable which is not uniform or trying to set a variable like "iDontExist".

Do I need to pause the pipeline, lock an element first or do something else?
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic change of glshader element

Holger
I created the pipeline in C because I thought there might be a problem with the python wrapper.
But the program crashes at the same function call.

// part of the pipeline
elGlshader = gst_element_factory_make("glshader", "shader");
g_object_set(G_OBJECT(elGlshader), "fragment", g_gcharShaderPrg, NULL);
g_timeout_add_seconds (1, timeout_cb, elGlshader);


// the pipeline is running as expected and crashes after the timer expires
static gboolean timeout_cb (gpointer user_data)
{
   g_print("Timer\n");
   GValue * value;
   GstGLShader *pShader;
   g_object_get_property(G_OBJECT(user_data),"shader", value);
   pShader = g_value_get_pointer(value);
   if (pShader != NULL)
   {
      gst_gl_shader_set_uniform_1f(pShader , "separation", -0.1); // Gives an exception violation
   }
   else
   {
      g_print("NO SHADER!!!\n");
   }
   return TRUE;
}

Calling gst_gl_shader.... causes a segmentation fault (as it does in python). Is my code wrong, did I forget to lock something or is it the same error described before???? I use the gst-1.8.3 on windows7.

Reply | Threaded
Open this post in threaded view
|

Re: Re: Dynamic change of glshader element

Matthew Waters
On 01/09/16 22:52, Holger wrote:

> I created the pipeline in C because I thought there might be a problem with
> the python wrapper.
> But the program crashes at the same function call.
>
> // part of the pipeline
> elGlshader = gst_element_factory_make("glshader", "shader");
> g_object_set(G_OBJECT(elGlshader), "fragment", g_gcharShaderPrg, NULL);
> g_timeout_add_seconds (1, timeout_cb, elGlshader);
>
>
> // the pipeline is running as expected and crashes after the timer expires
> static gboolean timeout_cb (gpointer user_data)
> {
>    g_print("Timer\n");
>    GValue * value;
>    GstGLShader *pShader;
>    g_object_get_property(G_OBJECT(user_data),"shader", value);
>    pShader = g_value_get_pointer(value);
>    if (pShader != NULL)
>    {
>       gst_gl_shader_set_uniform_1f(pShader , "separation", -0.1); // Gives
> an exception violation
In order to call gst_gl_shader_set_uniform* functions, you need to have
the shader in use (with gst_gl_shader_use()) and there be a GL context
active on the current thread.  This are standard OpenGL requirements and
GStreamer doesn't hide them from you.  If you don't have a GL context
readily available, the "create-shader" signal on glshader is executed
from a thread with a GL context and you can set the update-shader
property from any thread to have it signalled.  This way you can update
the shader/create a new shader in a thread with a GL context.

Cheers
-Matt

>    }
>    else
>    {
>       g_print("NO SHADER!!!\n");
>    }
>    return TRUE;
> }
>
> Calling gst_gl_shader.... causes a segmentation fault (as it does in
> python). Is my code wrong, did I forget to lock something or is it the same
> error described before???? I use the gst-1.8.3 on windows7.
>
>
>
>
>
> --
> View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Dynamic-change-of-glshader-element-tp4669514p4679352.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
>


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (514 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Re: Dynamic change of glshader element

Holger
My knowledge of opengl is very low - but I now know what you mean.
I added a callback for the create-shader signal in python. But I found no access over the passed element to  the running shader.
But there is another property which is working fine "uniforms". I didn't recognize it before...

It still was a horror to find the right python functions but now it's working for a dictionary with the uniforms as string and the value as float.

def update_uniforms(self, dictUniforms):
        stcUni = Gst.Structure.new_empty("uniforms")
        for k, v in dictUniforms.items():
            tmp = GObject.Value(GObject.TYPE_FLOAT)
            tmp.set_float(v)
            stcUni.set_value(k, tmp)

        self.elGlshader.set_property("uniforms", stcUni)

Maybe this might help someone else...