According to the OpenGL specification for sampler objects, the following applies:
If a sampler object and a texture object are simultaneously bound to
the same texture unit, then the sampling state for that unit is
taken from the sampler object (see section 3.9.2, "Sampler
Objects"). This can have an effect on the effective completeness of
the texture. In particular, if the texture is not mipmap complete
and the sampler object specifies a MIN_FILTER requiring mipmaps, the
texture will be considered incomplete for the purposes of that
texture unit. However, if the sampler object does not require
mipmaps, the texture object will be considered complete. This means
that a texture can be considered both complete and incomplete
simultaneously if it is bound to two or more texture units along
with sampler objects with different states.
However, if I don't generate any mipmaps for the texture I'm applying the sampler to, the texture just samples as black (probably because the texture is considered incomplete). Could this be because the driver automatically sets a MIN_FILTER, thus requiring mipmaps to be generated for a texture in order for it to be sampled properly? If so, this doesn't follow the specification, since a texture might not have mipmaps (such as render targets) but should still be able to have sampler objects to be bound to them. I've tried using a plain sampler using glGenSamplers(1, sampler) and applying it without setting any parameters, and I still get a black texture. I'm using Windows 7 64-bit with a Radeon 7970 with Catalyst 13.4.
Thanks in advance.
I worked around the problem by providing mipmaps for the texture, although this is not conforming to the specification. I've found another problem. This picture is using the following shader code:
float d1 = min(min(TriDistance.x, TriDistance.y), TriDistance.z); vec4 color = texture(DiffuseTexture, uv); Color = vec4(amplify(d1, 40.0f, -0.5f) * color.xyz, color.a);
I can't show the complete shader code since it's not in pure GLSL but rather in an intermediate language I'm developing. This is however the complete function body. Color is a vec4 output.
The result is the following:
The purple here is the border color which I've set to 1, 0, 1, 1. The specification states:
'The data in params specifies four values that define the border values that should be used for border texels. If a texel is sampled from the border of the texture, the values of GL_TEXTURE_BORDER_COLOR are interpreted as an RGBA color to match the texture's internal format and substituted for the non-existent texel data. If the texture contains depth components, the first component of GL_TEXTURE_BORDER_COLOR is interpreted as a depth value. The initial value is (0.0, 0.0, 0.0, 0.0).'
It seems like the border color is not substituted, but rather multiplied, which is wrong. This is true both when I use glTexParameter and glSamplerParameter to set the border color and wrap modes.
The aformentioned sampler problem relating to mipmaps seems to be resolvable by simply doing:
glUniform1i(this->uniformLocation, this->textureUnit); glBindSampler(this->textureUnit, 0); -- add this to make the problem go away glActiveTexture(GL_TEXTURE0 + this->textureUnit); glBindTexture(this->textureType, (GLint)this->currentValue);