PDA

View Full Version : Sending/Accessing Float data to/from Shader



James A.
08-17-2010, 07:07 AM
I'm using gl 3.3 core.

I have been using UBOs to access some float data in my shaders, indexing it with vertex attributes. but I'd like to try doing the same thing with a texture. And i have 2 questions:

1. I initially tried creating a VBO filling it with the data and then using
GL_PIXEL_UNPACK_BUFFER to transfer the data to a 1d texture, which did seem to get the data across, though i think i confused my formats as sending (1.0, 0, 0, 0) came out as blue.

I have also just read that it's possible to do this using Texture Buffers, which seems better as it doesn't require the transfer step.

Which would be the better option? Or is there a better way that i am unaware of.

2. regarding texture formats, I use glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, width, 0, GL_RGBA, GL_FLOAT, NULL); to create the texture and glTexSubImage1D(GL_TEXTURE_1D, 0, 0, width, GL_RGBA, GL_FLOAT, NULL); with the PBO to transfer my data across, is this correct? I'm not too sure on the definitions between internal format and type here.

thank you for any help.

DmitryM
08-17-2010, 10:25 AM
1. Texture buffers work good for me - no need for extra transfer between buffer storage and the texture.

2. Both glTexImage1D and glTexSubImage1D can transfer you data from the buffer object if it bound as GL_PIXEL_UNPACK_BUFFER. The internal format represents the way it's stored in GPU memory, while the type & format arguments specify the type of the input data (like 'external' from the point of view of GPU), taken from either PBO (if bound) or system memory (if given a pointer).

James A.
08-17-2010, 06:02 PM
Thank you for you answer DmitryM. I will try using Texture Buffers.

Does anyone know why when sending {1.0, 0.0, 0.0, 0.0} to a texture using glTexSubImage1D(GL_TEXTURE_1D, 0, 0, width, GL_RGBA, GL_FLOAT, NULL); using a buffer bound to GL_PIXEL_UNPACK_BUFFER the first colour in the texture appears to be blue. infact it seems a though only the 1st float affects the 1st colour, the 2nd float the 2nd pixel and so on (if i change the data to {0.0, 1.0, 0.0, 0.0} the 2nd pixel displays as blue)

The original texture was created using glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, width, 0, GL_RGBA, GL_FLOAT, NULL); and is 512 texels wide and i am just trying to replace the first colour.

James A.
08-18-2010, 05:44 AM
I got it, i was not using GL_FLOAT in glTexSubImage1D but GL_UNSIGNED_BYTE by mistake. thanks for your time and help :)