Resizing the texture in memory

Started by
9 comments, last by idinev 14 years, 8 months ago
I'm sitting here wondering if it is possible to resize the texture based on image data already loaded? Code-wise the resizing would ideally take place between glGenTextures and glBindTexture and glTexImage2D. I've been scanning through OpenGL references but I can't seem to find anything. Either there isn't one or my eyes are getting too sore :-/
Advertisement
Quote:Original post by _necrophilissimo_
I'm sitting here wondering if it is possible to resize the texture based on image data already loaded? Code-wise the resizing would ideally take place between glGenTextures and glBindTexture and glTexImage2D.

I've been scanning through OpenGL references but I can't seem to find anything. Either there isn't one or my eyes are getting too sore :-/
There isn't one. You can emulate this by allocating a new texture with the new size, and then using some form of render-to-texture (preferably FBO) to render the old texture into the new one with appropriate scaling.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by swiftcoder
There isn't one. You can emulate this by allocating a new texture with the new size, and then using some form of render-to-texture (preferably FBO) to render the old texture into the new one with appropriate scaling.


Thanks for the tip, but I already concidered that, but I cant go down that path; The whole purpose of this endevour of mine is to find a work-around to some videocards not accepting GL_TEXTURE_RECTANGLE extensions. The idea is to allow people using such cards to downscale the textures to power-of-2 dimensions. Render-to-texture doesn't work if the videocard can't render the texture, not to mention using FBO would force me to use even more extensions videocards of those users can't handle.

So, is there any other option (other than re-scaling the textures files or re-writing the actual image file reading routines)?
Quote:Original post by _necrophilissimo_
So, is there any other option (other than re-scaling the textures files or re-writing the actual image file reading routines)?
Do what gluBuild2DMipmaps does - rescale in software before uploading the texture to OpenGL.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

You can do it in the CPU, so it doesn't depend on any GL capabilities.
glBlitFramebufferEXT allows you to do resizing.

Regards
elFarto
If you want to scale, here is one way
glhScaleImage_asm386
http://www.geocities.com/vmelkon/glhlibrary.html
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by _necrophilissimo_
Thanks for the tip, but I already concidered that, but I cant go down that path; The whole purpose of this endevour of mine is to find a work-around to some videocards not accepting GL_TEXTURE_RECTANGLE extensions. The idea is to allow people using such cards to downscale the textures to power-of-2 dimensions.
To be honest, that is some truly ancient hardware you are targeting - the GeForce 2 MX had support for GL_ARB_texture_rectangle, as does my old Radeon 7000 mobility. Anything a couple of revisions newer than those two should support GL_ARB_texture_non_power_of_two as well...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Thanks, I'll look into all the options :)

Quote:Original post by swiftcoder
To be honest, that is some truly ancient hardware you are targeting - the GeForce 2 MX had support for GL_ARB_texture_rectangle, as does my old Radeon 7000 mobility. Anything a couple of revisions newer than those two should support GL_ARB_texture_non_power_of_two as well...


Well, yeah, I'm aiming at very low end. Judging by the feedback I've been getting surprisingly many people have faced issues ragarding the matter. The biggest offenders seem to be the integrated Intel Graphics chips. Apparently those things can run Vista Premium but can't handle rectangle OpenGL textures :-/
Quote:Original post by _necrophilissimo_
Well, yeah, I'm aiming at very low end. Judging by the feedback I've been getting surprisingly many people have faced issues ragarding the matter. The biggest offenders seem to be the integrated Intel Graphics chips. Apparently those things can run Vista Premium but can't handle rectangle OpenGL textures :-/
The Intel GMA X3100, X3500 and X4500 all support texture_rectangle, but sadly the very common GMA 950 does not.

However, you might want to consider why you need to use rectangular textures at all. The primary use of rectangular textures is usually render-to-texture, as they allow you to match the native dimensions of the back-buffer. Since the 950-class GMAs aren't really up to much render-to-texture, I assume this is for loaded textures instead, at which point you might as well use power-of-2 textures on *all* systems (and store the images that way).

Also keep in mind that many GPUs which claim to support rectangular textures (in particular, older ATI cards) take a *huge* performance hit (> 1200%) when sampling from rectangular textures.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement