PDA

View Full Version : One shader two images with different dimension



mobeen
02-16-2011, 04:28 AM
Hi all,
I have a scene where I am rendering two meshes each with a different texture with different sizes but a common shader. the texture unit 0 is used for the texture.
Since the texture unit 0 is active by default, I bind the texture of mesh 1 and draw it then i bind the texture of mesh 2 and draw it. This produces no error on my nvidia quadro fx 5600 but on an ATI Radeon HD 5570, it produces GL_INVALID_OPERATION. Upon investigating the matter in the glspec I find this (on page 190 core spec opengl 4.1),


The error INVALID_OPERATION is generated if an attempt is made
to bind a texture object of different dimensionality than the specified target.
So does this mean that in order to render meshes with the same shader, their textures must be having the same dimension if I intend to use the same texture unit for both?

mbentrup
02-16-2011, 05:08 AM
Dimensionality refers to the number of dimensions of your texture, so you cannot bind a 3D texture when the shaders samples a 2D texture. The size (= number of pixels) of the bound texture does not matter.

mobeen
02-16-2011, 05:15 AM
hmm ok thanks for the clarification.

ZbuffeR
02-16-2011, 06:52 AM
As I read this, "dimensionality" is more likely to refer to target attribute, one of TEXTURE_1D, TEXTURE_2D, TEXTURE_3D,
TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
TEXTURE_BUFFER, TEXTURE_CUBE_MAP, TEXTURE_2D_MULTISAMPLE, and
TEXTURE_2D_MULTISAMPLE_ARRAY.

Binding 2D textures only differing by width and height should not be a problem.

EDIT : made redundant by mbentrup :)

By the way, are you certain you see this error right after it has been generated ? Show some code around the problematic call.

mobeen
02-16-2011, 10:19 PM
Thanks mbentrup and ZBuffer, I nailed the problem. it was due to me not calling glGenTextures for each new texture. THe rest of the code was fine.