Webgl readPixels() invalid operation: invalid format/type combination

Dustin Silk

Im trying to read the RGBA values of a texture i have but it keeps returning the following error and every value comes out as 0:

WebGL: INVALID_OPERATION: readPixels: invalid format/type combination

Heres my code at initialisation where pixels is an array of texture values:

   texture = gl.createTexture()
   gl.activeTexture(gl.TEXTURE0)
   gl.bindTexture(gl.TEXTURE_2D, texture)
   gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1)
   gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, n, n, 0,
     gl.RGBA, gl.FLOAT, new Float32Array(pixels))

   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

   FBO = gl.createFramebuffer()

   gl.bindFramebuffer(gl.FRAMEBUFFER, FBO)
   gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
       gl.TEXTURE_2D, texture, 0)

And then later on, on a click event i run the following:

gl.bindFramebuffer(gl.FRAMEBUFFER, FBO);

var data = new Uint8Array(resolution * resolution * 4);
gl.readPixels(0, 0, resolution, resolution, gl.RGBA, gl.UNSIGNED_BYTE, data);

console.log(data)

Data returns a large array of zeros. What is the correct combination of format and type or where have i gone wrong here?

Dustin Silk

After using gl.getContext("experimental-webgl")

I managed to read the pixels of a float texture using the following:

  gl.bindFramebuffer(gl.FRAMEBUFFER, _this.myFrameBufferObject);
  var data = new Float32Array(resolution * resolution * 4);
  gl.readPixels(0,0,resolution,resolution,gl.RGBA,gl.FLOAT,data);

Credit goes to the comment below this answer

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

WebGL: INVALID_OPERATION: vertexAttribPointer: stride or offset not valid for type

From Dev

webGL readPixels and FireFox 35

From Dev

Why is this WebGL shader type invalid?

From Dev

why i got this error "WebGL: INVALID_OPERATION: drawArrays: front and back stencils settings do not match"

From Dev

three.js: WebGL: INVALID_OPERATION: bindTexture: object not from this context

From Dev

Invalid operation of opcode and operands

From Dev

Invalid argument to operation ++/--

From Dev

Invalid Floating Point Operation

From Dev

E: Invalid operation instal

From Dev

Invalid Operation with Decimal

From Dev

E: Invalid operation instal

From Dev

OpenGL Invalid Operation

From Dev

Invalid argument to operation ++/--

From Dev

glGenBuffers - GL_INVALID_OPERATION

From Dev

LWJGL glDrawArrays throws Invalid operation

From Dev

Deserialize XML Invalid Operation Exception

From Dev

GL ERROR: 1282 - Invalid operation

From Dev

Moving AX into CL - Invalid combination of opcode and operands

From Dev

ActionSheetPicker Invalid target/action combination used for ActionSheetPicker'

From Dev

torch.addmm received an invalid combination of arguments

From Dev

Invalid combination of button flags MOUSE 5 BUTTONS

From Dev

Invalid object name in a XML Path / Stuff combination

From Dev

Working around WebGL readPixels being slow

From Dev

glVertexAttribPointer GL_INVALID_OPERATION invalid vao vbo pointer usage

From Dev

GL_INVALID_OPERATION on Tesselation Shader

From Dev

Invalid floating point operation calling Trunc()

From Dev

OpenGL: INVALID_OPERATION following glEnableVertexAttribArray

From Dev

JDBC to hive connection fails on invalid operation isValid()

From Dev

Trying to install OpenFL - haxelib returns invalid operation

Related Related

  1. 1

    WebGL: INVALID_OPERATION: vertexAttribPointer: stride or offset not valid for type

  2. 2

    webGL readPixels and FireFox 35

  3. 3

    Why is this WebGL shader type invalid?

  4. 4

    why i got this error "WebGL: INVALID_OPERATION: drawArrays: front and back stencils settings do not match"

  5. 5

    three.js: WebGL: INVALID_OPERATION: bindTexture: object not from this context

  6. 6

    Invalid operation of opcode and operands

  7. 7

    Invalid argument to operation ++/--

  8. 8

    Invalid Floating Point Operation

  9. 9

    E: Invalid operation instal

  10. 10

    Invalid Operation with Decimal

  11. 11

    E: Invalid operation instal

  12. 12

    OpenGL Invalid Operation

  13. 13

    Invalid argument to operation ++/--

  14. 14

    glGenBuffers - GL_INVALID_OPERATION

  15. 15

    LWJGL glDrawArrays throws Invalid operation

  16. 16

    Deserialize XML Invalid Operation Exception

  17. 17

    GL ERROR: 1282 - Invalid operation

  18. 18

    Moving AX into CL - Invalid combination of opcode and operands

  19. 19

    ActionSheetPicker Invalid target/action combination used for ActionSheetPicker'

  20. 20

    torch.addmm received an invalid combination of arguments

  21. 21

    Invalid combination of button flags MOUSE 5 BUTTONS

  22. 22

    Invalid object name in a XML Path / Stuff combination

  23. 23

    Working around WebGL readPixels being slow

  24. 24

    glVertexAttribPointer GL_INVALID_OPERATION invalid vao vbo pointer usage

  25. 25

    GL_INVALID_OPERATION on Tesselation Shader

  26. 26

    Invalid floating point operation calling Trunc()

  27. 27

    OpenGL: INVALID_OPERATION following glEnableVertexAttribArray

  28. 28

    JDBC to hive connection fails on invalid operation isValid()

  29. 29

    Trying to install OpenFL - haxelib returns invalid operation

HotTag

Archive