opengl texture format for floating-point gpgpu -


i wish process image using glsl. instance - each pixel, output squared value: (r,g,b)-->(r^2,g^2,b^2). want read result cpu memory using glreadpixels.

this should simple. however, glsl examples find explain shaders image post-processing; thus, output value lies in [0,255]. in example, however, want output values in range [0^2,255^2]; , don't want them normalized [0,255].

the main parts of code (after trials , permutations):

glteximage2d(gl_texture_2d, 0, gl_rgba16f, width, height, 0, gl_bgr, gl_float, null); glreadpixels(0, 0, width, height, gl_rgb, gl_float, data_float);  

i don't post entire code since think these 2 lines problem lies.

edit

following @arttu's suggestion, , following this post , this post my code reads follows:

glteximage2d(gl_texture_rectangle_arb, 0, gl_rgba32f_arb, width, height, 0, gl_rgba, gl_float, null); glreadpixels(0, 0, width, height, gl_rgb, gl_float, data_float); 

still, not solve problem. if understand correctly - no matter what, input values scaled [0,1] when insert them. it's me multiply later 255 or 255^2...

using floating-point texture format keep values intact without clamping them specific range (in case, within limits of 16-bit float representation, of course). didn't specify opengl version, assumes 4.3.

you seem have conflicting format , internalformat. you're specifying internalformat rgba16f, format bgr, without alpha component (glteximage2d man page). try following:

glteximage2d(gl_texture_2d, 0, gl_rgba16f, width, height, 0, gl_bgra, gl_float, null); glreadpixels(0, 0, width, height, gl_rgba, gl_float, data_float); 

on first line you're specifying 2d texture four-component, 16-bit floating point format, , opengl expect texture data in bgra format. since have 0 last parameter, you're not specifying image data. remember rgba16f format gives half values in shader, implicitly casted 32-bit format if you're assigning values float or vec* variables.

on second line, you're downloading image data device data_float, time in rgba order.

if doesn't solve problem, you'll need include more code. also, adding glgeterror calls code find call causes error. luck :)


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -