Image of the viewport can no longer be obtained via glReadPixels in Python. Gives strange results since 2.83 #80471

Closed
opened 2020-09-04 15:36:35 +02:00 by Martin Grewe · 16 comments

System Information
Operating system: Arch Linux 5.8.5-arch1-1
Graphics card: Intel i7-8665U

Blender Version
Broken: since 2.83
Worked: till 2.82
Short description of error

In Python, we get an image of the viewport from within an registered draw handler routine using:

viewport = bgl.Buffer(bgl.GL_INT, 4)
bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport)
width = int(viewport[2])
height = int(viewport[3])
image = np.zeros([height, width, 4],dtype=np.uint8)
buffer = bgl.Buffer(bgl.GL_BYTE, image.shape, image)
bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer)

It worked fine till 2.82, as shown here
till2.82.jpg

However, it gives blackish colors of the objects in the viewport since 2.83:
since2.83.jpg

**System Information** Operating system: Arch Linux 5.8.5-arch1-1 Graphics card: Intel i7-8665U **Blender Version** Broken: since 2.83 Worked: till 2.82 **Short description of error** In Python, we get an image of the viewport from within an registered draw handler routine using: viewport = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport) width = int(viewport[2]) height = int(viewport[3]) image = np.zeros([height, width, 4],dtype=np.uint8) buffer = bgl.Buffer(bgl.GL_BYTE, image.shape, image) bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer) It worked fine till 2.82, as shown here ![till2.82.jpg](https://archive.blender.org/developer/F8840476/till2.82.jpg) However, it gives blackish colors of the objects in the viewport since 2.83: ![since2.83.jpg](https://archive.blender.org/developer/F8840477/since2.83.jpg)
Author

Added subscriber: @mgrewe

Added subscriber: @mgrewe
Martin Grewe changed title from Offloading of rendered viewport gives strange results since 2.83 to Image of the viewport obtained via Python gives strange results since 2.83 2020-09-04 16:04:01 +02:00
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

Just checking if I understand this correctly:

I've put your code [not exactly the same, left numpy out of play here for the time being] into an operator which seems to give correct results here (no black/unshaded object afaict):
#80471.blend

Does this fail for you as well?
If not, please provide a .blend file with your code failing -- with the complete code to run from the Text Editor (including saving the image or dumping the data into a blender Image datablock)

Just checking if I understand this correctly: I've put your code [not exactly the same, left numpy out of play here for the time being] into an operator which seems to give correct results here (no black/unshaded object afaict): [#80471.blend](https://archive.blender.org/developer/F8843421/T80471.blend) Does this fail for you as well? If not, please provide a .blend file with your code failing -- with the complete code to run from the Text Editor (including saving the image or dumping the data into a blender Image datablock)
Author

Hi Philipp,

thanks for the reply. Please find an updated blend file attached which should give what I tried to describe above. You might need to toggle "Generated Image".

#80471.blend

2.82:
2.82.jpg

2.90:
2.90.jpg

Hi Philipp, thanks for the reply. Please find an updated blend file attached which should give what I tried to describe above. You might need to toggle "Generated Image". [#80471.blend](https://archive.blender.org/developer/F8843894/T80471.blend) 2.82: ![2.82.jpg](https://archive.blender.org/developer/F8843899/2.82.jpg) 2.90: ![2.90.jpg](https://archive.blender.org/developer/F8843901/2.90.jpg)

Added subscriber: @fclem

Added subscriber: @fclem

This is expected. We separated the overlay drawing and the render in 2.83. So glReadPixels will return the overlays color only (because the callbacks are rendered on the overlay framebuffer).

We still have to figure how to give access to the render color buffer.

It is unpractical for us to give access to the final framebuffer as it is now the window framebuffer.

This is expected. We separated the overlay drawing and the render in 2.83. So glReadPixels will return the overlays color only (because the callbacks are rendered on the overlay framebuffer). We still have to figure how to give access to the render color buffer. It is unpractical for us to give access to the final framebuffer as it is now the window framebuffer.

Changed status from 'Needs User Info' to: 'Confirmed'

Changed status from 'Needs User Info' to: 'Confirmed'
Author

Thanks for investigation. I hope the access can be done fast as we use it as an option to stream the viewport in a time-critical application. Pl. let me know if I can be of any help, e.g. testing. Cheers, Martin

Thanks for investigation. I hope the access can be done fast as we use it as an option to stream the viewport in a time-critical application. Pl. let me know if I can be of any help, e.g. testing. Cheers, Martin
Campbell Barton changed title from Image of the viewport obtained via Python gives strange results since 2.83 to Image of the viewport can no longer be obtained via glReadPixels in Python. Gives strange results since 2.83 2020-09-15 08:20:05 +02:00

Added subscriber: @chafouin

Added subscriber: @chafouin

Added subscriber: @JoseConseco

Added subscriber: @JoseConseco

Added subscriber: @unwave

Added subscriber: @unwave
Author

Hi all, just wanted to push this since a way to get the viewport image is still needed.

Is there maybe another way to get access to the rendered image? I want to avoid offscreen rendering due to additional overhead.

Hi all, just wanted to push this since a way to get the viewport image is still needed. Is there maybe another way to get access to the rendered image? I want to avoid offscreen rendering due to additional overhead.
Contributor

Added subscriber: @p2or

Added subscriber: @p2or

Added subscriber: @Will-43

Added subscriber: @Will-43
Philipp Oeser removed the
Interest
EEVEE & Viewport
label 2023-02-09 15:14:30 +01:00

We still have to figure out how to give access to the render color buffer.

As far as I know, it is possible to access frambeuffer through the drawing callbacks and the gpu module.
Therefore I believe we can consider this report resolved.

> We still have to figure out how to give access to the render color buffer. As far as I know, it is possible to access frambeuffer through the drawing callbacks and the gpu module. Therefore I believe we can consider this report resolved.
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-10-10 20:45:39 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
9 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#80471
No description provided.