help visualising the contents of Integer textures

I’m trying to visualise the contents of my picking texture (based on an article here Picking), but so far I just get access violations when attempting to do so.

I have a tried and tested texture manager which has the ability to display the textures in cache. It draws a rectangle in the lower left of the screen for the texture’s RGB contents, and then a second rectangle to the right of the first showing the contents of the Alpha chanel. The texture manager UI is able to handle 2D, 3D & texture_arrays in any format (fixed point RGBA8, floating point textures, framebuffer depth, shadow maps, etc).

Now, I have added support for Integer and Unsigned Integer textures and have created a visualisation shader to aid in displaying the contents of the textures.


/*
Render Unsigned Integer texture to framebuffer
Note: Tere is no way to display the contents of Integer/Unsigned integer textures
as their content is meaninless.


We will assume we are using the integer texture formats for Picking, and therefore the contents
of the 3 channels are used i the follwoing way:

RED = Scene manager index (batchattributes.PickingID) - max 30 scene objects
GREEN= Material Index (max 150 materials?)
BLUE = Primitive ID (assume max of 655535 triangles per render call)

ALPHA = undefined

*/
#version 150 compatibility


varying vec4 vertexcolor;

uniform usampler2D UISampler;		//Unsigned Integer RGBA texture - for Picking
uniform float slice;			//used to switch between displaying RGB and alpha channel.


void main()
{
  uvec4 color = texture(UISampler, gl_TexCoord[0].xy);	//sample the Unsigned integer texture uniform
  
//Note: to display an integer texture, convert all values to floats
  
  
  if (slice > 1.0 )	//User Interface want to display only alpha channel
  {
   float alpha_color = float(color.a) / 1.0;
   gl_FragColor = vec4(alpha_color, alpha_color, alpha_color, 1.0);
  }
  else gl_FragColor = vec4(float(color.r) / 30.0, float(color.g) / 150.0, float(color.b) / 65535.0, 1.0);
  
  
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
  
}

My problem is that after drawing the two quads onto the main framebuffer, I get an access violation on my AMD radeon 4850 (Cat 11.10 Preview2). The really strange thing is the access violation accurs when I unbind the shader with

gluseprogram(0)

You’ll notice I try and convert the integer texture colour values into floating point values so that the ‘colour’ can be displayed.

On previous attempts to debug this, I didn’t perform the conversion in the shader, which resulted in getting access violations before a draw call had even been submitted - the violation happens when I call

 glColor4f (1,1,1,4.0) 

…which is the line before I submit a glVertex command to display the Alpha values.

[Yes i know the alpha value is above 1.0 - it has a meaning in my code. When the alpha > 1.0, the shader takes a branch and it draws the contents of the alpha channel instead of the RGA values.]
The interesting part here is that the first quad displaying the RGB values has already been executed and it’s only on the Alpha visualisation the failure occurs.

So, becuase of the odd issues involving glColor4f, I switched the shader (posted above) to use a uniform value rather than the incomming alpha colour value to determine whetheror not to draw the alpha channel. Now the access violation occurs as I first said - when unbinding the shader.

FYI: Opengl 3.3 compatibility profile. The Framebuffer’s Unsigned integer texture is using GL_RGBA32UI internal format.

Tried glFinish after every gl function called?
This looks very fishy, but then again counting on driver bugs being predictable isn’t the best idea :wink:

Perhaps you do something strange before the visualization?

Also, since you have 3.3, you could get away with using GL_RGBA32F texture and using uint <-> float casting functions introduced in GLSL 330 (if you suspect integer texture to be the problem).

I have written the picking code to work with float texture or integer now. With float32 format everything works just fine but I would like to work with integer textures as it’s a better fit for picking IDs.
I must admit I have not even thought about glFinish after each line of code. May reveal something.