5

I'm working on a Mac application using OpenGL textures that I load from image files on disk using glTexImage2D.

According to the docs, for OpenGL versions >= 2.0, textures can be any arbitrary size. (for versions <2.0, the x and y dimensions both have to be a power of 2.)

However, I am getting bad textures if my image dimensions are not an even multiple of 4. I've searched and searched, but can't find any documentation on this requirement. In fact, the "red book" explicitly states that the texture dimensions can be any value for version >= 2.0.

What am I missing?

And, is there a performance benefit to converting a texture to the next largest power-of-two dimension? My app will require Mac OS 10.6.6 or later, which should run on any Intel Mac. Some of the early Intel macs had very "humble" graphics hardware.

Any help would be greatly appreciated.

Duncan C
  • 128,072
  • 22
  • 173
  • 272

2 Answers2

5

The constraint on ordinary textures having dimensions being powers of 2 remains in OpenGL versions >= 2. However there is a new texture target supported, GL_TEXTURE_RECTANGLE, which supports arbitrary dimensions, but won't do mipmaping.

There's no constraint on dimensions being multiples of 4, however I suspect you might have glPixelStore(GL_UNPACK...) parameters set, maybe set by other parts of the program, that cause this behaviour.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • 3
    This is not correct. OpenGL 2.0 introduced non-power of two textures. GL_TEXTURE_RECTANGLE is also for NPOT textures, but it limits to unnormalized coords and no mipmaps, and it's core in OpenGL 3.x – Dr. Snoopy Jan 27 '11 at 18:30
  • 6
    +1 : glPixelStore(GL_UNPACK_ALIGNMENT, 1) is probably your friend if you upload RGB textures without padding on end of each row. – rotoglup Jan 27 '11 at 21:17
  • @Matias Valdenegro: Thanks, didn't knew that. Something to learn everyday. – datenwolf Jan 27 '11 at 22:12
  • @rotoglup please post your comment as an answer so I can upvote it. You saved my day :) – kaoD Mar 16 '12 at 17:10
0

What format are your textures? S3TC compressed texture formats operate on 4x4 tiles, so may not work or may have visual artifacts if the dimensions are not multiples of 4.

Alan
  • 4,897
  • 2
  • 24
  • 17
  • I'm trying to write code that will create a texture from any RGB or RGBA image loaded from disk in a variety of formats (JPEG, TIFF, PNG, GIFF.) Mac OS is good about converting these to a consistent internal format that I can then convert to a texture, except getting the image to the correct multiple-of-4 size is proving a headache. I tried creating a second image at a multiple-of-4 size and drawing my first image into it, but that creates an internal NSImageRep (Cocoa object) of type NSCGImageSnapshotRep, which does not let me read the image data. Sometimes I hate class clusters. – Duncan C Jan 27 '11 at 20:13