# Emscripten: WebGL: INVALID\_ENUM: readPixels: invalid format

**URL:** https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565
**Category:** Web
**Created:** [November 4, 2020, 5:14pm UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565 "2020-11-04T17:14:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ZigaSajovic](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zigasajovic/32/2566_2.png) [@ZigaSajovic](https://discourse.vtk.org/u/ZigaSajovic)
#### Post date: [November 4, 2020, 5:14pm UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/1 "2020-11-04T17:14:39Z")

</div>

When using `vtkOpenGLHardwareSelector` one gets two errors

> WebGL: INVALID\_ENUM: readPixels: invalid format  
> and  
> GL\_INVALID\_OPERATION: Invalid format and type combination.

The errors arise from the javascript call

```js
GLctx.readPixels(x, y, width, height, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap))

```

in the generated code. This is triggered with the call to

```c++
vtkOpenGLHardwareSelector * h_sel = //...
// ...
h_sel->CaptureBuffers();

```

Hence the same error occurs with `PickProp` on a renderer

```c++
vtkRenderer *r = // ...
// ...
r->PickProp(x, y);

```

The same behavior is observed with `vtkOpenGLRenderer`.

Please note that everything was compiled in compliance with instructions on the Examples page, and that other features work correctly.

Might anyone offer some insight into what might be happening? The `CaptureBuffers` method of `vtkHardwareSelector` invokes `render_window->Render()` under the hood, but this method seems to work properly outside of the above.

---

<div class="post-metadata">

### Author: ![Kevin\_Jiang](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kevin_jiang/32/3817_2.png) [@Kevin\_Jiang](https://discourse.vtk.org/u/Kevin_Jiang)
#### Post date: [October 14, 2021, 4:14am UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/2 "2021-10-14T04:14:08Z")

</div>

I also encountered the same problem, Mr. Ziga Sajovic, do you have an answer at last?

---

<div class="post-metadata">

### Author: ![aji](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@aji](https://discourse.vtk.org/u/aji)
#### Post date: [September 11, 2022, 7:14am UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/3 "2022-09-11T07:14:53Z")

</div>

Any update. I am also getting same error. Thanks

---

<div class="post-metadata">

### Author: ![aji](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@aji](https://discourse.vtk.org/u/aji)
#### Post date: [September 12, 2022, 2:42am UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/4 "2022-09-12T02:42:05Z")

</div>

@Sebastien_Jourdain I am developing app where user need to pick actor. However it appears picking operation is not working in web. Can you please suggest any workaround.

Thanks a lot.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [September 12, 2022, 2:11pm UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/5 "2022-09-12T14:11:47Z")

</div>

vtk.js support actor picking. I think the issue with VTK/wasm is that the code from the GL/C++ is not compatible with its webgl counterpart.

---

<div class="post-metadata">

### Author: ![aji](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@aji](https://discourse.vtk.org/u/aji)
#### Post date: [September 12, 2022, 5:30pm UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/6 "2022-09-12T17:30:08Z")

</div>

Thanks @Sebastien_Jourdain for quick response. Yes I am working on both VTK.js and VTK/wasm. Picking operations are working fine in VTK.js. But performance of VTK.js decreases as number of actors increases. In my case I have few thousand of actors. On other hand VTK/wasm work like a charm. I tested with 3000 actors and it worked smoothly. However I was disappointed to see picking operation is not working in otherwise a very good product. From your comment it appears to be changing few libraries.

Would it be possible for you or somebody to guide me how to fix this? I shall be very thankful.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [September 12, 2022, 5:43pm UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/7 "2022-09-12T17:43:53Z")

</div>

To fix that part, the GL code will need to have some ifdef pass specific so the webgl conversion can actually work. But unfortunately, I don’t know who can help right now on that topic. @thewtex would you know?

---

<div class="post-metadata">

### Author: ![aji](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@aji](https://discourse.vtk.org/u/aji)
#### Post date: [September 13, 2022, 3:17am UTC](https://discourse.vtk.org/t/emscripten-webgl-invalid-enum-readpixels-invalid-format/4565/8 "2022-09-13T03:17:20Z")

</div>

@thewtex I noticed there is already a issue for this.

> <https://github.com/InsightSoftwareConsortium/itk-wasm/issues/346>
>
> I am trying several operations for newly updated VTK with emscripten rendering.
> …
> 
> I found that \[Picking Example\](https://vtk.org/Wiki/VTK/Examples/Cxx/Interaction/Picking) seems not working for now.
> 
> Getting 2D coordinates works fine, but \`vtkPropPicker-\>Pick(...)\` returns warning and wrong results.
> 
> \`\`\`
> 
> virtual void OnLeftButtonDown() override
> {
> int\* clickPos = this-\>GetInteractor()-\>GetEventPosition();
> 
> 
> // Pick from this location.
> vtkSmartPointer\<vtkPropPicker\> picker = vtkSmartPointer\<vtkPropPicker\>::New();
> picker-\>Pick(clickPos\[0\], clickPos\[1\], 0, this-\>GetDefaultRenderer());
> 
> double\* pos = picker-\>GetPickPosition();
> std::cout \<\< "Pick position (world coordinates) is: " \<\< pos\[0\] \<\< " " \<\< pos\[1\] \<\< " " \<\< pos\[2\] \<\< std::endl;
> std::cout \<\< "Picked actor: " \<\< picker-\>GetActor() \<\< std::endl;
> \`\`\`
> 
> The picked position in world coordinates is always 0 0 0, and the browser shows warning saying : 
> 
> 
> \`\`\`
> WebGL: INVALID\_ENUM: readPixels: invalid format
> 
>   | \_glReadPixels | @ | Picking.js:11102 -- | -- | -- | --
>   | vtkOpenGLRenderWindow::GetZbufferData(int, int, int, int, float\*) | @ | 018741d6:1
>   | vtkOpenGLRenderWindow::GetZbufferData(int, int, int, int) | @ | 018741d6:1
>   | vtkHardwareSelector::BuildPropHitList(unsigned char\*) | @ | 018741d6:1
>   | vtkHardwareSelector::ProcessPixelBuffers() | @ | 018741d6:1
>   | vtkHardwareSelector::Render(vtkRenderer\*, vtkProp\*\*, int) | @ | 018741d6:1
>   | vtkOpenGLRenderer::UpdateGeometry(vtkFrameBufferObjectBase\*) | @ | 018741d6:1
>   | vtkOpenGLRenderer::DeviceRender() | @ | 018741d6:1
>   | vtkRenderer::Render() | @ | 018741d6:1
>   | vtkRendererCollection::Render() | @ | 018741d6:1
>   | vtkRenderWindow::DoStereoRender() | @ | 018741d6:1
>   | vtkRenderWindow::Render() | @ | 018741d6:1
>   | vtkOpenGLRenderWindow::Render() | @ | 018741d6:1
>   | vtkHardwareSelector::CaptureBuffers() | @ | 018741d6:1
>   | vtkHardwareSelector::Select() | @ | 018741d6:1
>   | vtkRenderer::PickProp(double, double, double, double) | @ | 018741d6:1
>   | vtkRenderer::PickProp(double, double) | @ | 018741d6:1
>   | vtkViewport::PickPropFrom(double, double, vtkPropCollection\*) | @ | 018741d6:1
>   | vtkPropPicker::PickProp(double, double, vtkRenderer\*) | @ | 018741d6:1
>   | vtkPropPicker::Pick(double, double, double, vtkRenderer\*) | @ | 018741d6:1
>   | MouseInteractorStyle2::OnLeftButtonDown() | @ | 018741d6:1
> 
> 
> \`\`\`
> \`\`\`
> \[.WebGL-000001CEB1519F40\] GL\_INVALID\_OPERATION: Invalid format and type combination.
> \`\`\`

Can you please guide in this regard how to address?

Thanks
