3

textureSize is a handy function to get texture dimensions in a shader without having to pass them in by hand as uniforms.

Is there a similar API for image units?

jozxyqk
  • 16,424
  • 12
  • 91
  • 180
  • Image units do not have sizes, the same way texture units do not. The image that is currently bound to it, on the other hand has a size. – Andon M. Coleman Jun 03 '14 at 00:19
  • Fair enough, but if I were to ask a question about an "image" it leads to a lot of ambiguity google wise. There really should be a more explicit name for texture-bount-to-image-unit that isn't "image". – jozxyqk Jun 03 '14 at 09:45
  • Yeah, part of the problem is that you do not bind textures to image units. You bind images... many textures are actually composed of multiple images as far as GL is concerned (each LOD in a texture's mip-chain, for instance, is an image). D3D calls them [subresources](http://msdn.microsoft.com/en-us/library/windows/desktop/ff476901(v=vs.85).aspx), avoiding that sort of confusion, but at the same time to the layman: *"what the hell is a subresource?"* :P -- I think *image* is a more descriptive term, and am glad GL did not adopt D3D's generic approach to naming resources. – Andon M. Coleman Jun 03 '14 at 15:13

1 Answers1

5

Yes, it's in OpenGL 4.3:

Example:

layout(rgba32f) uniform image2D myImage;
...
ivec2 size = imageSize(myImage);
jozxyqk
  • 16,424
  • 12
  • 91
  • 180