Problem compiling shader

Hello board,

I’m trying to get a particular shader (code is pasted below) to write to each element of gl_FragData. However, when I try to compile the shader, it gives me a rather unexplainable error:
(0) : fatal error C9999: marking a sampler that is not a scalar


#version 120

uniform sampler2DRect input_image[gl_MaxDrawBuffers];

void main()
{
  vec2 coord = (gl_TexCoord[0].xy - 0.5) * 2.0 + 0.5;
  
  for (int i = 0; i < gl_MaxDrawBuffers; i++)
  {
    gl_FragData[i] = texture2DRect(input_image[i], coord);
  }
}

I tried a couple of other things and it also gave me a rather weird error:
(0) : fatal error C9999: Array access to non-array

The code I used to get that error is below (notice the 0 instead of i in gl_TexCoord)


#version 120

uniform sampler2DRect input_image[gl_MaxDrawBuffers];

void main()
{
  vec2 coord = (gl_TexCoord[0].xy - 0.5) * 2.0 + 0.5;
  
  for (int i = 0; i < 2; i++)
  {
    gl_FragData[i] = texture2DRect(input_image[0], coord);
  }
}

I couldn’t really get my head around it, but I saw it in other places on the net, so I couldn’t really think that there was something wrong with my code. As a final solution, I replaced the for loop by the code that the for loop should have executed. This code ran just fine. Too bad this didn’t give me an explanation why the others didn’t work.


#version 120

uniform sampler2DRect input_image[gl_MaxDrawBuffers];

void main()
{
  vec2 coord = (gl_TexCoord[0].xy - 0.5) * 2.0 + 0.5;
  
  gl_FragData[0] = texture2DRect(input_image[0], coord);
  gl_FragData[1] = texture2DRect(input_image[1], coord);
  gl_FragData[2] = texture2DRect(input_image[2], coord);
  gl_FragData[3] = texture2DRect(input_image[3], coord);
  gl_FragData[4] = texture2DRect(input_image[4], coord);
  gl_FragData[5] = texture2DRect(input_image[5], coord);
  gl_FragData[6] = texture2DRect(input_image[6], coord);
  gl_FragData[7] = texture2DRect(input_image[7], coord);
}

I’m running Mac OS X 10.5.6, Gefore 9400M, GLSL version 1.2. I’m using PyOpenGL 3.0.0c1 to run my OpenGL and GLSL code. Hope somebody can make heads or tails out of it, cause I sure can’t.

I have seen a few posts on the Apple threads about similar problems with looping / indexing, although most had to do with ATI cards to be honest…

In most cases the fix was to unroll the loop.

I am a bit unsure of the integer / array indexing restrictions in GLSL on the various GPUs and drivers right now, but thought the nVidia’s were fairly flexible.

Well, guess not. At least not the drivers for Mac os X. I can unroll the loop, but I wanted to support a dynamic range of writable buffers. I wanted to make use of the maximum writable buffers available. Since most now support up to 4 buffers and some already up to 16, it’s kinda hard to unroll the loop when I don’t really know how big it is. Maybe I could do something with define-like-structures, but it’s gonna be quite ugly. Wish those variables just worked :S

Your initial fragment shader throws an error that you need to add “#extension GL_ARB_texture_rectangle : enable” to the code.
Once added after the #version line, the shader compiled without issues for me under XP64 with 181.20 drivers.
Means you probably need a new Mac driver.

Yea, after much tinkering with my Python/C code I got it to run just fine on my Windows machine. So I guess it’s a pure driver problem and not a GLSL/OpenGL problem.

The #extension and #version is not required when you run the code on a Mac (at least not with my drivers). Once I ran the stuff on my Windows machine, I saw that I needed to add those. Not that I made any difference on my Mac, but I guess it’s neater to add those :slight_smile:

Too bad I cannot really find new MBP-video drivers. Guess I’ll have to live with this bug for a while.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.