[4/4] egl: Detect and print GLES version
diff mbox series

Message ID 20260110170927.79918-5-robert.mader@collabora.com
State New
Headers show
Series
  • GPUISP cleanups
Related show

Commit Message

Robert Mader Jan. 10, 2026, 5:09 p.m. UTC
It might come in handy to know whether 2.0 or e.g. 3.2 is used.

Signed-off-by: Robert Mader <robert.mader@collabora.com>
---
 include/libcamera/internal/egl.h |  1 +
 src/libcamera/egl.cpp            | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

Comments

Barnabás Pőcze Jan. 10, 2026, 5:48 p.m. UTC | #1
Hi

2026. 01. 10. 18:09 keltezéssel, Robert Mader írta:
> It might come in handy to know whether 2.0 or e.g. 3.2 is used.
> 
> Signed-off-by: Robert Mader <robert.mader@collabora.com>
> ---
>   include/libcamera/internal/egl.h |  1 +
>   src/libcamera/egl.cpp            | 17 +++++++++++++++++
>   2 files changed, 18 insertions(+)
> 
> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
> index 21e2aa9df..f007f448a 100644
> --- a/include/libcamera/internal/egl.h
> +++ b/include/libcamera/internal/egl.h
> @@ -136,5 +136,6 @@ private:
>   	PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
>   	PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
>   	PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
> +	PFNGLGETSTRINGPROC glGetString;
>   };
>   } //namespace libcamera
> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
> index 0bd9a83be..0ffd008c7 100644
> --- a/src/libcamera/egl.cpp
> +++ b/src/libcamera/egl.cpp
> @@ -288,6 +288,10 @@ int eGL::initEGLContext(GBM *gbmContext)
>   	EGLint major;
>   	EGLint minor;
>   
> +	const char *glVersion;
> +	EGLint glMajor;
> +	EGLint glMinor;
> +
>   	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
>   		LOG(eGL, Error) << "API bind fail";
>   		goto fail;
> @@ -327,6 +331,12 @@ int eGL::initEGLContext(GBM *gbmContext)
>   		goto fail;
>   	}
>   
> +	glGetString = (PFNGLGETSTRINGPROC)eglGetProcAddress("glGetString");
> +	if (!glGetString) {
> +		LOG(eGL, Error) << "glGetString not found";
> +		goto fail;
> +	}
> +
>   	if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) {
>   		LOG(eGL, Error) << "eglChooseConfig fail";
>   		goto fail;
> @@ -342,6 +352,13 @@ int eGL::initEGLContext(GBM *gbmContext)
>   
>   	makeCurrent();
>   
> +	glVersion = (const char *)glGetString(GL_VERSION);

const char *glVersion = reinterpret_cast<const char *>(glGetString(GL_VERSION));


> +	if (glVersion &&
> +	    sscanf(glVersion, "OpenGL ES %d.%d", &glMajor, &glMinor) == 2 &&
> +	    glMajor > 0 && glMinor >= 0) {
> +		LOG(eGL, Info) << "GLES: version: " << glMajor << "." << glMinor;

Is there any reason not to just print the string as is? I think it not much
harder to read and would avoid the need for the string parsing.


Regards,
Barnabás Pőcze

> +	}
> +
>   	return 0;
>   fail:
>
Robert Mader Jan. 10, 2026, 7:01 p.m. UTC | #2
Hi, thanks for the feedback.

On 10.01.26 18:48, Barnabás Pőcze wrote:
> Hi
>
> 2026. 01. 10. 18:09 keltezéssel, Robert Mader írta:
>> It might come in handy to know whether 2.0 or e.g. 3.2 is used.
>>
>> Signed-off-by: Robert Mader <robert.mader@collabora.com>
>> ---
>>   include/libcamera/internal/egl.h |  1 +
>>   src/libcamera/egl.cpp            | 17 +++++++++++++++++
>>   2 files changed, 18 insertions(+)
>>
>> diff --git a/include/libcamera/internal/egl.h 
>> b/include/libcamera/internal/egl.h
>> index 21e2aa9df..f007f448a 100644
>> --- a/include/libcamera/internal/egl.h
>> +++ b/include/libcamera/internal/egl.h
>> @@ -136,5 +136,6 @@ private:
>>       PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
>>       PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
>>       PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
>> +    PFNGLGETSTRINGPROC glGetString;
>>   };
>>   } //namespace libcamera
>> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
>> index 0bd9a83be..0ffd008c7 100644
>> --- a/src/libcamera/egl.cpp
>> +++ b/src/libcamera/egl.cpp
>> @@ -288,6 +288,10 @@ int eGL::initEGLContext(GBM *gbmContext)
>>       EGLint major;
>>       EGLint minor;
>>   +    const char *glVersion;
>> +    EGLint glMajor;
>> +    EGLint glMinor;
>> +
>>       if (!eglBindAPI(EGL_OPENGL_ES_API)) {
>>           LOG(eGL, Error) << "API bind fail";
>>           goto fail;
>> @@ -327,6 +331,12 @@ int eGL::initEGLContext(GBM *gbmContext)
>>           goto fail;
>>       }
>>   +    glGetString = 
>> (PFNGLGETSTRINGPROC)eglGetProcAddress("glGetString");
>> +    if (!glGetString) {
>> +        LOG(eGL, Error) << "glGetString not found";
>> +        goto fail;
>> +    }
>> +
>>       if (eglChooseConfig(display_, configAttribs, &config, 1, 
>> &numConfigs) != EGL_TRUE) {
>>           LOG(eGL, Error) << "eglChooseConfig fail";
>>           goto fail;
>> @@ -342,6 +352,13 @@ int eGL::initEGLContext(GBM *gbmContext)
>>         makeCurrent();
>>   +    glVersion = (const char *)glGetString(GL_VERSION);
>
> const char *glVersion = reinterpret_cast<const char 
> *>(glGetString(GL_VERSION));
>
>
>> +    if (glVersion &&
>> +        sscanf(glVersion, "OpenGL ES %d.%d", &glMajor, &glMinor) == 
>> 2 &&
>> +        glMajor > 0 && glMinor >= 0) {
>> +        LOG(eGL, Info) << "GLES: version: " << glMajor << "." << 
>> glMinor;
>
> Is there any reason not to just print the string as is? I think it not 
> much
> harder to read and would avoid the need for the string parsing.

True, will do in v2!

>
>
> Regards,
> Barnabás Pőcze
>
>> +    }
>> +
>>       return 0;
>>   fail:
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index 21e2aa9df..f007f448a 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -136,5 +136,6 @@  private:
 	PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
 	PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
 	PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
+	PFNGLGETSTRINGPROC glGetString;
 };
 } //namespace libcamera
diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index 0bd9a83be..0ffd008c7 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -288,6 +288,10 @@  int eGL::initEGLContext(GBM *gbmContext)
 	EGLint major;
 	EGLint minor;
 
+	const char *glVersion;
+	EGLint glMajor;
+	EGLint glMinor;
+
 	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
 		LOG(eGL, Error) << "API bind fail";
 		goto fail;
@@ -327,6 +331,12 @@  int eGL::initEGLContext(GBM *gbmContext)
 		goto fail;
 	}
 
+	glGetString = (PFNGLGETSTRINGPROC)eglGetProcAddress("glGetString");
+	if (!glGetString) {
+		LOG(eGL, Error) << "glGetString not found";
+		goto fail;
+	}
+
 	if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) {
 		LOG(eGL, Error) << "eglChooseConfig fail";
 		goto fail;
@@ -342,6 +352,13 @@  int eGL::initEGLContext(GBM *gbmContext)
 
 	makeCurrent();
 
+	glVersion = (const char *)glGetString(GL_VERSION);
+	if (glVersion &&
+	    sscanf(glVersion, "OpenGL ES %d.%d", &glMajor, &glMinor) == 2 &&
+	    glMajor > 0 && glMinor >= 0) {
+		LOG(eGL, Info) << "GLES: version: " << glMajor << "." << glMinor;
+	}
+
 	return 0;
 fail: