PDA

View Full Version : glTexImage2D with 16F textures?



Leadwerks
03-13-2009, 01:14 PM
According to the texture_float spec:


Accepted by the <internalFormat> parameter of TexImage1D,
TexImage2D, and TexImage3D:

RGBA32F_ARB 0x8814
RGB32F_ARB 0x8815
ALPHA32F_ARB 0x8816
INTENSITY32F_ARB 0x8817
LUMINANCE32F_ARB 0x8818
LUMINANCE_ALPHA32F_ARB 0x8819
RGBA16F_ARB 0x881A
RGB16F_ARB 0x881B
ALPHA16F_ARB 0x881C
INTENSITY16F_ARB 0x881D
LUMINANCE16F_ARB 0x881E
LUMINANCE_ALPHA16F_ARB 0x881F

That's great, but what can I use in the <format> parameter of glTexImage2D()? If I have all my pixel data and want to send it to the 16F texture, how the heck do I do that if the <format> parameter doesn't accept GL_INTENSITY16F or GL_LUMINANCE16F?

These are the values that <format> can accept. How can I turn a grid of 16-bit short values into 16F data on the GPU?:

GL_COLOR_INDEX, GL_RED, GL_GREEN, GL_BLUE,
GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, and
GL_LUMINANCE_ALPHA.

ZbuffeR
03-13-2009, 01:48 PM
Apparently you have to use pixel data with classic floats, 32bits wide instead of 16.

format = GL_RGB // or GL_RGBA
type = GL_FLOAT // 32bits floats

Leadwerks
03-13-2009, 02:02 PM
That's hilarious. I have been using GL_UNSIGNED_BYTE since the beginning of time, and it didn't even occur to me to change it. I don't even see it anymore. XD

I'm trying this right now. Looks like it is working:
glTexImage2D GL_TEXTURE_2D,0,GL_LUMINANCE16F_ARB,resolution,res olution,0,GL_LUMINANCE,GL_UNSIGNED_SHORT,heightarr ay

Leadwerks
03-13-2009, 04:26 PM
Is there a reason glTexSubImage2D does not work with float textures? What if I want to modify my terrain heightmap data dynamically?

ZbuffeR
03-13-2009, 04:56 PM
It should work, uploading float32 data to 16f texture, something like this :
glTexImage2D GL_TEXTURE_2D,0,GL_LUMINANCE16F_ARB,resolution,res olution,0,GL_LUMINANCE,GL_FLOAT,heightarray

Leadwerks
03-13-2009, 05:05 PM
TexImage2D works fine, but according to the spec and my own attempt, glTexSubImage2D does not. I don't want to update the whole texture, only part of it.

Ilian Dinev
03-13-2009, 07:55 PM
Maybe this is a solution:

typedef struct{
IL_TEX_FORMAT ilfmt;
GLenum iformat;
GLenum format;
GLenum storage;
bool IsCompressed;
int pixelSize;
}TEX_FORMAT;
{ILTEXFMT_RGBA16, GL_FLOAT_RGBA16_NV,GL_RGBA,GL_HALF_FLOAT_NV,false, 8},

Ilian Dinev
03-13-2009, 09:26 PM
or simply
GL_HALF_FLOAT_ARB

Leadwerks
03-13-2009, 09:34 PM
I don't follow.

Ilian Dinev
03-14-2009, 03:49 AM
I mean, why not use the RG16F format instead? 16bpp textures aren't natively supported anyway, afaik.
http://developer.nvidia.com/object/nv_ogl_texture_formats.html

GL_RG, GL_RG16F, GL_HALF_FLOAT_ARB are the params to the teximage2d, I think.

Leadwerks
03-14-2009, 01:02 PM
1. I am talking about glTexSubImage2D, not glTexImage2D.

2. Is this format supported on ATI cards?

martinsm
03-14-2009, 02:08 PM
2. On HDxxx cards it is supported, don't know about previous generations. This format is in ARB_texture_rg extension spec.

Leadwerks
03-14-2009, 08:48 PM
Oh duh, glTexSubImage doesn't even care what the existing texture format is. How embarrassing.