Get OpenGLgadget() context number?

Just starting out? Need help? Post your questions and find answers here.
User avatar
naf
User
User
Posts: 18
Joined: Fri Aug 18, 2023 3:19 pm
Location: Europe

Get OpenGLgadget() context number?

Post by naf »

The setter

Code: Select all

#PB_OpenGL_SetContext
is useful, but there is no getter, like maybe #PB_OpenGL_GetContext.

Code: Select all

GetGadgetAttribute(openGLgadgetNum, #PB_OpenGL_SetContext )
only returns 0, not working.
The same question came when using wegGL / webView: viewtopic.php?p=636229#p636229
In practice, the first opened OpenGLgadget() gets context 0, the second one has context = 1, and so on. It works. But becomes unusable when the user has the freedom to dynamically create and and close windows and their OpenGLgadget()'s. The context number is needed after dynamic creation of an OpenGLgadget().
Is there a quick workaround by importing something from a library and skipping the standard GetGadgetAttribute() ?
Thanks. (PB v.6.21 on linux Zorin with Wayland, msi GP72 2QE Leopard Pro)
pjay
Enthusiast
Enthusiast
Posts: 291
Joined: Thu Mar 30, 2006 11:14 am

Re: Get OpenGLgadget() context number?

Post by pjay »

I've used this code, but only tested on Windows:

Code: Select all

Procedure glGetCurrentContext()
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows : ProcedureReturn wglGetCurrentContext_()
    CompilerCase #PB_OS_Linux : ProcedureReturn glxGetCurrentContext_()
    CompilerCase #PB_OS_MacOS : ProcedureReturn CGLGetCurrentContext_()
  CompilerEndSelect
EndProcedure
 
OpenWindow(0,0,0,1280,480,"")
OpenGLGadget(0,0,0,640,480) : Debug glGetCurrentContext()
OpenGLGadget(1,640,0,640,480) : Debug glGetCurrentContext()

SetGadgetAttribute(0, #PB_OpenGL_SetContext, 1) : Debug glGetCurrentContext()
SetGadgetAttribute(1, #PB_OpenGL_SetContext, 1) : Debug glGetCurrentContext()
User avatar
naf
User
User
Posts: 18
Joined: Fri Aug 18, 2023 3:19 pm
Location: Europe

Re: Get OpenGLgadget() context number?

Post by naf »

Nice trick! The glX functions are for the X11server though, don't work with wayland. I find no equivalent for wayland, or I would need to use the restricted ES (for Embedded Systems), with EGL.
I will try using a single context, hidden, resizing it before each draw to an offscreen framebuffer/renderbuffer, and finally transfering the image to the screen as an image gadget. Anyone is welcome to try it before me. See how much the frame rate is impacted.
For Wayland, you can use EGL as an alternative to glXGetCurrentContext(). Specifically, using libGLESv2 instead of libGL can help avoid issues related to glX calls. GitHub
X11 and Wayland differ significantly in how they manage OpenGL contexts. X11 uses a client-server model where applications send rendering commands to the X server, which handles the OpenGL context. In contrast, Wayland applications manage their own OpenGL contexts directly, communicating with the compositor for final display. This direct approach in Wayland reduces latency and improves performance by eliminating the need for an intermediary server. glukhov.org abhik.ai
User avatar
mk-soft
Always Here
Always Here
Posts: 6603
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Get OpenGLgadget() context number?

Post by mk-soft »

As I know, the OpenGLGadget does not work under Wayland because Wayland does not have an interface to OpenGL ...
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
Post Reply