Strange link error when using samplerCube

This is a little long but I want to be as clear as possible.

Here is a brief description of my problem: I am successfully rendering a simple scene using deferred shading and light maps. Everything looks great. I’m now attempting to create an omnidirectional light map using a GL_TEXTURE_CUBE_MAP. In the fragment shader for the light pass that reads said cube map, I am reading from, and checking the value of, the texture using something like:

uniform samplerCube tShadowMapCube;
float zBuffer = textureCube(tShadowMapCube, -normalized_frag_to_light_vector).z;
gl_FragColor = vec4(zBuffer, zBuffer, zBuffer, 1.0);

where normalized_frag_to_light_vector is a vec3 that is what it says. This produces a link error. What is the error you ask? Well, the info log doesn’t have anything in it, so I don’t know!

I can verify that I usually get an error message when a link error is produced, like “ERROR: 0:32: error(#172) Too many arguments constructor” or some such thing. No error message is given in this case.

I can verify that normalized_frag_to_light_vector holds sensible values, because if I just ignore the light map and use normalized_frag_to_light_vector to produce plain, unshadowed lighting, it works perfectly. Also, it’s the same as what is in the directional light fragment shader, which works perfectly.

The most puzzling thing is this: If I simply ignore the link error, everything works as expected. The code snippet above produces exactly the expected results, and shows that it’s reading sensible values from the samplerCube.

Another puzzling thing is that if I replace normalized_frag_to_light_vector in the snippet above with something like vec3(texCoord, 1.0), where texCoord is the varying vec2 representing the GBuffer coordinates, then no link error is produced (but obviously that’s not where I want to sample the samplerCube from). I can also replace it with something like vec3(any constant values here) and no link error is produced.

So, what is going on? Is there something obvious I’m missing?

Here are lots of details (I can provide more if you need):

I’m using Java with the the “jogl-1.1.1-rc8-linux-amd64” version of JOGL (maybe this is a bit old?). I have an Radeon HD 6700, using Catalyst 11.12 drivers for linux (maybe this has some problems?). Output from relevant glGetStrings:

GL_VENDOR: ATI Technologies Inc.
GL_RENDERER: AMD Radeon HD 6700 Series
GL_VERSION: 4.2.11318 Compatibility Profile Context

The full fragment shader is here (obviously this will produce weird looking results, but I’m just testing the cube map values, and if I ignore the link error, the results are exactly what one would expect).

#ifdef GL_ES
precision highp float;

uniform vec3 lightPosition;
uniform vec3 lightColor;

uniform sampler2D tColor;
uniform sampler2D tPosition;
uniform sampler2D tNormal;

uniform samplerCube tShadowMapCube;

varying vec2 texCoord;

void main()
    //read gbuffer data
	vec4 color = vec4(vec3(texture2D(tColor, texCoord)), 1.0);
	vec3 fragPosition = vec3(texture2D(tPosition, texCoord));
	vec3 normal = vec3(texture2D(tNormal, texCoord));

	//get dist and normalized vector from vertex to light
	vec3 frag_to_light_vector = lightPosition - fragPosition;
	float d = length(frag_to_light_vector);
	vec3 normalized_frag_to_light_vector = frag_to_light_vector / d;

	//get cube map value
	//if I use either commented version of ltf, no link error is produced
	//vec3 ltf = vec3(1.0, 1.0, 1.0);
	//vec3 ltf = vec3(texCoord.xy, 1.0);
	vec3 ltf = -normalized_frag_to_light_vector;
	float zBuffer = textureCube(tShadowMapCube, ltf).z;
	gl_FragColor = vec4(zBuffer, zBuffer, zBuffer, 1.0);

Here is the code that is finding the link error:

private void checkLinkAndValidationErrors(GL gl, int id) {
        IntBuffer status = BufferUtil.newIntBuffer(1);
        gl.glGetProgramiv(id, GL.GL_LINK_STATUS, status);

        if (status.get() == GL.GL_FALSE) {
            getInfoLog(gl, id);
        } else {
            gl.glGetProgramiv(id, GL.GL_VALIDATE_STATUS, status);
            if (status.get() == GL.GL_FALSE) {
                getInfoLog(gl, id);
            } else {
                System.out.println("Successfully linked program " + id);

    private void getInfoLog(GL gl, int id) {
        IntBuffer infoLogLength = BufferUtil.newIntBuffer(1);
        gl.glGetShaderiv(id, GL.GL_INFO_LOG_LENGTH, infoLogLength);

        ByteBuffer infoLog = BufferUtil.newByteBuffer(infoLogLength.get(0));
        gl.glGetShaderInfoLog(id, infoLogLength.get(0), null, infoLog);

        String infoLogString =
        throw new Error("Shader compile error
" + infoLogString);

Which is referred to in the following (if I simply comment out the “checkLinkAndValidationErrors”, everything works as expected)

public ShaderLightPassShadowedCube(GL gl){

		int v = gl.glCreateShader(GL.GL_VERTEX_SHADER);
		int f = gl.glCreateShader(GL.GL_FRAGMENT_SHADER);

		//read shader sources and compile
		gl.glShaderSource(v, 1, readShaderResource("ShaderLightPassVert.glsl"), null);
		checkCompileError(gl, v);

		gl.glShaderSource(f, 1, readShaderResource("ShaderLightPassShadowedCubeFrag.glsl"), null);
		checkCompileError(gl, f);

		//create shader program and attach shaders
		shaderProgram = gl.glCreateProgram();
		gl.glAttachShader(shaderProgram, v);
		gl.glAttachShader(shaderProgram, f);

		gl.glBindAttribLocation(shaderProgram, 0, "vertexPosition");
		gl.glBindAttribLocation(shaderProgram, 1, "vertexTex");
		//link the shader program
		//if I simply comment this out, everything works as expected
		checkLinkAndValidationErrors(gl, shaderProgram);

		//get locations of data arrays
		vertexPositionAttribute = gl.glGetAttribLocation(shaderProgram, "vertexPosition");
		vertexTexAttribute = gl.glGetAttribLocation(shaderProgram, "vertexTex");

		//some lighting info
		lightPositionUniform = gl.glGetUniformLocation(shaderProgram, "lightPosition");
	    lightColorUniform = gl.glGetUniformLocation(shaderProgram, "lightColor");
		//these are the gbuffer "textures"
	    tColorUniform = gl.glGetUniformLocation(shaderProgram, "tColor");
	    tPositionUniform = gl.glGetUniformLocation(shaderProgram, "tPosition");
	    tNormalUniform = gl.glGetUniformLocation(shaderProgram, "tNormal");

		//this is the light map texture
		tShadowMapCubeUniform = gl.glGetUniformLocation(shaderProgram, "tShadowMapCube");

This is super long now and I’m not even sure what more of the code would be relevant to post, since, as I said, everything is producing correct results if I just ignore the strange, uninformative link error. I can post whatever else you’d like to see, though.

Here’s another piece of code that might be relevant: The TEXTURE_CUBE_MAP I’m rendering to is created like this:

		//create texture
		int[] createTexIDs = new int[1];
		gl.glGenTextures(createTexIDs.length, createTexIDs, 0);
		texidCube = createTexIDs[0];
		gl.glBindTexture(GL.GL_TEXTURE_CUBE_MAP, texidCube);
		for(int i=0; i<6; i++){

		gl.glBindTexture(GL.GL_TEXTURE_CUBE_MAP, 0);

Where width and height happen to be fixed at 512 in this case. I attach to the current FBO for rendering to the light map like this:

	private void attach(GL gl, int i){
		//attach texture

		//check if it worked
		int status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
			throw new Error("Can't initialize an FBO render texture. FBO initialization failed.");

When rendering I loop through i=0 to i=5; for each i I call attach(gl, i), and render. Later, when I bind the texture for the lighting pass, I do:

	    gl.glBindTexture(GL.GL_TEXTURE_CUBE_MAP, texidCube);

I tried changing all of the above to use GL_RGBA8_ARB, GL_RGBA16F_ARB, and various other formats as a GL_COLOR_ATTACHMENT0_EXT instead of a GL_DEPTH_ATTACHMENT_EXT, but in all cases I tried, I get exactly the same result: The link error is produced or not in the same way as the original post, and if it is ignored, I see the correct color values.

Ok, just to be really complete, here are more glGetStrings:


GL_EXTENSIONS: GL_AMDX_debug_output GL_AMDX_vertex_shader_tessellator GL_AMD_conservative_depth GL_AMD_debug_output GL_AMD_depth_clamp_separate GL_AMD_draw_buffers_blend GL_AMD_multi_draw_indirect GL_AMD_name_gen_delete GL_AMD_performance_monitor GL_AMD_pinned_memory GL_AMD_sample_positions GL_AMD_seamless_cubemap_per_texture GL_AMD_shader_stencil_export GL_AMD_shader_trace GL_AMD_texture_cube_map_array GL_AMD_texture_texture4 GL_AMD_transform_feedback3_lines_triangles GL_AMD_vertex_shader_tessellator GL_ARB_ES2_compatibility GL_ARB_base_instance GL_ARB_blend_func_extended GL_ARB_color_buffer_float GL_ARB_compressed_texture_pixel_storage GL_ARB_conservative_depth GL_ARB_copy_buffer GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_draw_buffers GL_ARB_draw_buffers_blend GL_ARB_draw_elements_base_vertex GL_ARB_draw_indirect GL_ARB_draw_instanced GL_ARB_explicit_attrib_location GL_ARB_fragment_coord_conventions GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4 GL_ARB_get_program_binary GL_ARB_gpu_shader5 GL_ARB_gpu_shader_fp64 GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_imaging GL_ARB_instanced_arrays GL_ARB_internalformat_query GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_provoking_vertex GL_ARB_sample_shading GL_ARB_sampler_objects GL_ARB_seamless_cube_map GL_ARB_separate_shader_objects GL_ARB_shader_atomic_counters GL_ARB_shader_bit_encoding GL_ARB_shader_image_load_store GL_ARB_shader_objects GL_ARB_shader_precision GL_ARB_shader_stencil_export GL_ARB_shader_subroutine GL_ARB_shader_texture_lod GL_ARB_shading_language_100 GL_ARB_shading_language_420pack GL_ARB_shading_language_packing GL_ARB_shadow GL_ARB_shadow_ambient GL_ARB_sync GL_ARB_tessellation_shader GL_ARB_texture_border_clamp GL_ARB_texture_buffer_object GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_compression GL_ARB_texture_compression_bptc GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_cube_map_array GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float GL_ARB_texture_gather GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample GL_ARB_texture_non_power_of_two GL_ARB_texture_query_lod GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_texture_rgb10_a2ui GL_ARB_texture_snorm GL_ARB_texture_storage GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 GL_ARB_transform_feedback_instanced GL_ARB_transpose_matrix GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra GL_ARB_vertex_array_object GL_ARB_vertex_attrib_64bit GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_viewport_array GL_ARB_window_pos GL_ATI_draw_buffers GL_ATI_envmap_bumpmap GL_ATI_fragment_shader GL_ATI_meminfo GL_ATI_separate_stencil GL_ATI_texture_compression_3dc GL_ATI_texture_env_combine3 GL_ATI_texture_float GL_ATI_texture_mirror_once GL_EXT_abgr GL_EXT_bgra GL_EXT_bindable_uniform GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_compiled_vertex_array GL_EXT_copy_buffer GL_EXT_copy_texture GL_EXT_direct_state_access GL_EXT_draw_buffers2 GL_EXT_draw_instanced GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters GL_EXT_gpu_shader4 GL_EXT_histogram GL_EXT_multi_draw_arrays GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_packed_pixels GL_EXT_pixel_buffer_object GL_EXT_point_parameters GL_EXT_provoking_vertex GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_shader_image_load_store GL_EXT_shadow_funcs GL_EXT_stencil_wrap GL_EXT_subtexture GL_EXT_texgen_reflection GL_EXT_texture3D GL_EXT_texture_array GL_EXT_texture_buffer_object GL_EXT_texture_compression_bptc GL_EXT_texture_compression_latc GL_EXT_texture_compression_rgtc GL_EXT_texture_compression_s3tc GL_EXT_texture_cube_map GL_EXT_texture_edge_clamp GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 GL_EXT_texture_filter_anisotropic GL_EXT_texture_integer GL_EXT_texture_lod GL_EXT_texture_lod_bias GL_EXT_texture_mirror_clamp GL_EXT_texture_object GL_EXT_texture_rectangle GL_EXT_texture_sRGB GL_EXT_texture_shared_exponent GL_EXT_texture_snorm GL_EXT_texture_storage GL_EXT_texture_swizzle GL_EXT_timer_query GL_EXT_transform_feedback GL_EXT_vertex_array GL_EXT_vertex_array_bgra GL_EXT_vertex_attrib_64bit GL_IBM_texture_mirrored_repeat GL_KTX_buffer_region GL_NV_blend_square GL_NV_conditional_render GL_NV_copy_depth_to_color GL_NV_explicit_multisample GL_NV_float_buffer GL_NV_half_float GL_NV_primitive_restart GL_NV_texgen_reflection GL_NV_texture_barrier GL_SGIS_generate_mipmap GL_SGIS_texture_edge_clamp GL_SGIS_texture_lod GL_SUN_multi_draw_arrays GL_WIN_swap_hint WGL_EXT_swap_control

Try to do validation after you have assigned sensible values to all sampler uniforms. To quote the specs:

Paragraph: Validation

If the current set of active program objects cannot be executed, no primitives are
processed and the error INVALID_OPERATION will be generated.
This error is generated by any command that transfers vertices to the GL if:

  • Any two active samplers in the current program object are of different types,
    but refer to the same texture image unit.

ValidateProgram will check for all the conditions that could lead to an
INVALID_OPERATION error when rendering commands are issued, and may check
for other conditions as well…

Whoops, I guess I should have checked if it was a link error or validation error! You nailed it exactly… I rewrote all the error checks more carefully, separating the link and validation checks, and moved the validation error check to after the uniforms are set. Now everything works perfectly. I guess that’s what I get for being lazy and copying that part of the code from a tutorial, and not reading the specs :slight_smile:

So to clarify, when creating a shader program, link errors should be checked right after it is linked, but validation errors should not be checked until after uniforms are set? (Contrary to every tutorial I’ve looked at, which is a little frustrating, but again that’s what I get for relying on tutorials…) Do I really need to bother actually validating it every time uniforms are set, every frame…? Or should I just do it the first time they are set (assuming I’m setting them the same way every time)?

Validation is generally not something you need to do at all. It’s useful for catching errors, but it’s not important if your program works.

Basically, it’s something you should do during development if you detect a problem.

Note: Getting shader errors is also something you shouldn’t necessarily do in production code. Some shader compilers try to do the compilation in a separate thread. Which means the compilation state and infolog may not be immediately available. Attempts to get them basically force a sync, throwing away the whole point of threaded compilation.

That makes sense, I suspected that was the case but it’s good to know for sure. Thanks for the help!

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