chris838
chris838

Reputation: 5178

Using mipmap filtering on iOS 5.0 OpenGL ES 2.0 texture caches

I'm using a texture cache to draw video frames to the screen, just like the RosyWriter sample application from Apple.

I want to downsample an image from 1080p down to around 320x480 (for various reasons, I don't want to capture at a lower resolution) and use mipmap filtering to get rid of aliasing. However, when I try adding:

glGenerateMipmap(CVOpenGLESTextureGetTarget(inputTexture));
glTexParameteri(CVOpenGLESTextureGetTarget(inputTexture), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

I just get a black screen, as though the mipmaps aren't being generated. I'm rendering offscreen from one texture to another. Both source and destination are mapped to pixel buffers using texture caches.

Upvotes: 0

Views: 2663

Answers (1)

Brad Larson
Brad Larson

Reputation: 170317

Mipmaps can only be generated for power-of-two sized textures. None of the video frame sizes returned by the iOS cameras that I can think of have power-of-two dimensions. For using the texture caches while still generating mipmaps, I think you'd have to do something like do an offscreen re-render of the texture to a power-of-two FBO backed by a texture, then generate a mipmap for that.

That said, this is probably not the best way to accomplish what you want. Mipmaps only help when making a texture smaller on the screen, not making it larger. Also, they are pretty slow to generate at runtime, so this would drag your entire video processing down.

What kind of aliasing are you seeing when you zoom in? The normal hardware texture filtering should produce a reasonably smooth image when zoomed in on a video frame. As an example of this, grab and run the FilterShowcase sample from my GPUImage framework and look at the Crop filter. Zooming in on a section of the video that way seems to smooth things out pretty nicely, just using hardware filtering.

I do employ mipmaps for smooth downsampling of large images in the framework (see the GPUImagePicture when smoothlyScaleOutput is set to YES), but again that's for shrinking an image, not zooming in on it.

Upvotes: 2

Related Questions