Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI4 dual display with common context #8

Closed
ArtArt0 opened this issue Jan 27, 2020 · 9 comments
Closed

PI4 dual display with common context #8

ArtArt0 opened this issue Jan 27, 2020 · 9 comments

Comments

@ArtArt0
Copy link

ArtArt0 commented Jan 27, 2020

Hi!

I ran an issue:
when I use the code with LCD and HDMI display together, I can not activate the second display (and surface) errorless.

First I use context 1:
eglMakeCurrent(ctx->eglDisplay, ctx->eglSurface, ctx->eglSurface, ctx->eglContext)

Than the context 2 with the same eglContext:
eglMakeCurrent(ctx2->eglDisplay, ctx2->eglSurface, ctx2->eglSurface, ctx->eglContext)

And the second gives EGL_BAD_CONTEXT.

Anyway if I use in the second one with ctx2->eglContext at the 4th parameter, it succeeded, but it gives a blank screen (because the ctx2 contains nothing)

What is the problem? Can U give me an example for using 2 displays with the same eglContext?

@matusnovak
Copy link
Owner

Hi @ArtArt0

Are you using Raspberry Pi 4? How is the LCD connected to the board?

@ArtArt0
Copy link
Author

ArtArt0 commented Jan 27, 2020

With the standard cable (for the official 7'' LCD). Why? It shows the console successfully.

@matusnovak
Copy link
Owner

Are you able to get any OpenGL output if you use only the LCD display without second HDMI screen? (I am trying to figure out if this is DRM device problem or EGL problem).

@ArtArt0
Copy link
Author

ArtArt0 commented Jan 27, 2020

Yes, I have no problem with it.

@matusnovak
Copy link
Owner

I am not 100% sure because I haven't tried two displays, but I think you may need to call eglInitialize twice, once for the LCD display and second time for the HDMI display. As seen here: https://github.com/matusnovak/rpi-opengl-without-x/blob/master/triangle_rpi4.c#L48 with the correct EGLDisplay.

The drmModeGetResources and drmModeGetResources is used to get the EGLDisplay as shown here: https://github.com/matusnovak/rpi-opengl-without-x/blob/master/triangle_rpi4.c#L48 so I believe you should have two resources for your two displays.

Could you try iterating over the drmModeRes *resources as shown here: https://github.com/matusnovak/rpi-opengl-without-x/blob/master/triangle_rpi4.c#L28 and check if you have multiple connectors? It may be that you have two connectors that are DRM_MODE_CONNECTED. When you get the connector C structure then you can iterate over the connector->modes to get the resolution to identify the display.

@ArtArt0
Copy link
Author

ArtArt0 commented Jan 28, 2020

Finally I think I figured out!

The problem was in the getDisplay(): the gbm_create_device must call only once, and the second display uses the first gbmDevice struct.

Anyway the cardX device must open once too.

@matusnovak
Copy link
Owner

Awesome! You would be willing to share the code? I would like to give it a try and maybe make a sample code out of it and put it here in this repository.

And yeah, the device /dev/dri/card1 is the GPU so selecting card0 would not work. I originally thought the cardX is the HDMI<->GPU port (or something like that) but I was wrong.

@ArtArt0
Copy link
Author

ArtArt0 commented Jan 29, 2020

Sorry, I can not share it, but I hope it easy to implement to anyone now.

Anyway not always the card1 is the right one. You should detect with the following mode:

open card0
if not OK or getdisplay is not OK:
  open card1
  if OK:
    getdisplay

@matusnovak
Copy link
Owner

That's alright. I will play around with that when I get the chance and will create a sample code as well.

Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants