Samplers of different types use the same textur

Gidday Im getting this error, when I add cubemaps to a program & compile & validate

[b]Program validate log:
Validation Failed: Sampler error:
Samplers of different types use the same texture image unit.

  • or -
    A sampler’s texture unit is out of range (greater than max allowed or negative).[/b]

/////////////////////////////////////
heres the important parts of the program

[b]uniform sampler2D TEX0;
uniform samplerCube environmentMap;

gl_FragColor.xyz = (texture2D(TEX0, varTexcoord.st).xyz + textureCube( environmentMap, R.xyz ).xyz;[/b]

but how can either of these error’s be?

  1. Samplers of different types use the same texture image unit.

how can it know?
since you must first compile & validate the program before u use glUniform1i( loc, val ); to say what texture units you use
same with
2. A sampler’s texture unit is out of range (greater than max allowed or negative).

the only way it knows this is if it somehow has travelled into the future! :slight_smile: as its telling me my unit is invalid before I even say what unit Im using

NOTE - this is on an apple software opengl (for IOS), the above works on PC/linux and webgl

Am I overlooking something?, cheers zed

Hi,
Could u show us what val contains in this line


glUniform1i( loc, val ); 

Usually val is the texture unit where the texture is bound to. In your case since u have two different textures, they should be bound to different texture units. In other words, something along thes lines should work.


glUniform1i( locEnvSampler, 0); //set envMap to tex unit 0
glUniform1i( locTexSampler, 1); //set tex to tex unit 1
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, envTexID);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texID);

See if this helps.

Hi, you can set your samplers locations right after you’ve checked that the program linked successfully.
I.e. something like this:
glLinkProgram(progID);

GLint linked;
glGetProgramiv(progID, GL_LINK_STATUS, &linked);
if ( !linked ) handle_error_here;

glBindProgram(progID);

// here you can use glUniform1i() to set the sampler units

glBindProgram(0);

// now validate the program
glValidateProgram(progID);
GLint valid=1;
glGetProgramiv(progID, GL_VALIDATE_STATUS, &valid);
if ( !valid ) handle_error_here;

Datsua is correct.

glValidateProgram() is validating current context state (the sampler uniforms, the draw framebuffer, the current vertex array state, etc— anything that can cause a draw-time error when used with the program.) You shouldn’t validate immediately after linking.

Really you should validate right before drawing. And only in your debug build; it’s a tool for you to debug with.

Thanks heaps guys that was it,
Im very surprised Ive never been bitten by this before

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