Jump to content
  • Advertisement
Sign in to follow this  
DerTherion

OpenGL GLSL problem with uniform

This topic is 3410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, i am using openGL with java and the GLSL i got an crazy problem and i dont know what to do. in java i send some data to the fragment shader: int ed = gl.glGetUniformLocationARB(program, "edges"); gl.glUniform4fARB(ed, 1.0f,1.0f,1.0f,1.0f); that works... (i also do this for textures etc) in the fragment shader: uniform vec4 edges; int off=0; int ec1; sampler2D tex[10]; //an array of sampler2d that is filled one time inside the fragment shader(that work perfect) ... void main(void) { ... ... ... //and here is the problem if (edges.r==0.0) ec1 = int (0); if (edges.r==1.0) ec1 = int (1); if (edges.r==2.0) ec1 = int (2); if (edges.r==3.0) ec1 = int (3); ... //that will crash and i dont know why?!?!?! texel_av = texture2D(tex[ec1] , texCoord)*pow1; //that work texel_av = texture2D(tex[0] , texCoord)*pow1; texel_av = texture2D(tex[1] , texCoord)*pow1; texel_av = texture2D(tex[2] , texCoord)*pow1; texel_av = texture2D(tex[3] , texCoord)*pow1; i dont know what to do..why is the fragment shader blocking all my basic like attempts to build some simple integer access to an array (and work with static vars inside the fragement)

Share this post


Link to post
Share on other sites
Advertisement
is it crashing or what??

If it is just saying that it cannot find the uniform it might be becouse your using 'texel_av =' rather then 'texel_av +=' which means the compiler might remove all but the last one. and then remove all unused varibles which might include the uniform.. would need more info on the error...

Share this post


Link to post
Share on other sites
Why are you declaring ec1 and off outside of main? If they're not uniform, varying or attribute variables, put them inside of your main function. Maybe that's the problem.

Share this post


Link to post
Share on other sites
the problem is that i am not able to work with uniform data(int)

its simple: i got an array of sampler2d..

that array works perfect when calling tex[ec1]
and ec is static (inside or outside the main of the fragment code)

but at this moment when i try to use any data from outside
the frament shader stops the work

uniform int data1;

main...

sampler2d ( tex[data1] <- that stops the frag shader

or

test1=0;
if (data1==1) test1=1;
sampler2d ( tex[test1] <- that stops the fragment shader too


....

test1=1;
sampler2d ( tex[test1] <- that works





Share this post


Link to post
Share on other sites
gl.glUseProgramObjectARB(program);

int ed=gl.glGetUniformLocationARB(program, "edges");
gl.glUniform4fARB(ed, 0.0f,1.0f,0.0f,1.0f);



even this simple example fails:

//copy the working sampler2D t0 to tex0
if (edges.r==0.0) tex0=t0;

edges is filled with the correct data..but the fs
stops working when i use edges in any combination
with the sampler2d (direct and nodirect)



Share this post


Link to post
Share on other sites
Quote:
//that will crash and i dont know why?!?!?!
texel_av = texture2D(tex[ec1] , texCoord)*pow1;


It shouldn't cause a crash. Update your drivers to get the latest.
If then you still have problems, it's possible to send a bug report to the company so that they correct their driver problem.

Share this post


Link to post
Share on other sites
I mean, how do you initialize this vector:

sampler2D tex[10];

How is this filled? I believed that you only could pass sampler2D as uniforms.

Share this post


Link to post
Share on other sites
i now understand what you asking about:

first i was trying to get the sampler2d tex[10]
as a uniform..that was not working so
i try an unprofessional way...

i get the uniform sampler2d t0,t1,t2,t3,t4,t5...

and then i copy them to tex (tex[0]=t0;tex[1]=t1...}

and that is all working perfect with no error

the problem in a short example:

static int var1= 1
uniform int var2; //var2 gets the int=1 from main code

sampler2d [tex[var1]... is working
sampler2d [tex[var2]... is not working (yes,var2 got data)


update:

this is working!!!


"vec4 texel_av=0;\n" +


" if (edges.r==0.0) texel_av += texture2D(tex0 , texCoord)*pow1;\n" +
" if (edges.r==1.0) texel_av += texture2D(tex1 , texCoord)*pow1;\n" +
" if (edges.r==2.0) texel_av += texture2D(tex2 , texCoord)*pow1;\n" +
" if (edges.r==3.0) texel_av += texture2D(tex3 , texCoord)*pow1;\n" +

" if (edges.g==0.0) texel_av += texture2D(tex0 , texCoord)*pow4;\n" +
" if (edges.g==1.0) texel_av += texture2D(tex1 , texCoord)*pow4;\n" +
" if (edges.g==2.0) texel_av += texture2D(tex2 , texCoord)*pow4;\n" +
" if (edges.g==3.0) texel_av += texture2D(tex3 , texCoord)*pow4;\n" +

" if (edges.b==0.0) texel_av += texture2D(tex0 , texCoord)*pow2;\n" +
" if (edges.b==1.0) texel_av += texture2D(tex1 , texCoord)*pow2;\n" +
" if (edges.b==2.0) texel_av += texture2D(tex2 , texCoord)*pow2;\n" +
" if (edges.b==3.0) texel_av += texture2D(tex3 , texCoord)*pow2;\n" +

" if (edges.a==0.0) texel_av += texture2D(tex0 , texCoord)*pow3;\n" +
" if (edges.a==1.0) texel_av += texture2D(tex1 , texCoord)*pow3;\n" +
" if (edges.a==2.0) texel_av += texture2D(tex2 , texCoord)*pow3;\n" +
" if (edges.a==3.0) texel_av += texture2D(tex3 , texCoord)*pow3;\n" +


[Edited by - DerTherion on March 16, 2009 4:51:43 AM]

Share this post


Link to post
Share on other sites
Quote:
static int var1= 1
uniform int var2; //var2 gets the int=1 from main code

sampler2d [tex[var1]... is working
sampler2d [tex[var2]... is not working (yes,var2 got data)


That's normal. It isn't supported. But still, it should cause your system to crash. Instead, it should give a error log.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!