[v13,6/7] libcamera: software_isp: Prepare texture methods for LSC data
diff mbox series

Message ID 20260810201957.19623-7-mzamazal@redhat.com
State Superseded
Headers show
Series
  • LSC for SoftISP simple pipeline
Related show

Commit Message

Milan Zamazal Aug. 10, 2026, 8:19 p.m. UTC
Lens shading correction data is represented by textures.  Let's adjust
the signatures of eGL texture handling methods:

- Generalise createTexture2D for different formats.

- Add `const' to `data' argument to be able to accept std::array data.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 include/libcamera/internal/egl.h           |  8 ++++++--
 src/libcamera/egl.cpp                      | 14 ++++++++++----
 src/libcamera/software_isp/debayer_egl.cpp |  6 +++++-
 3 files changed, 21 insertions(+), 7 deletions(-)

Comments

Barnabás Pőcze Aug. 18, 2026, 10:13 a.m. UTC | #1
2026. 08. 10. 22:19 keltezéssel, Milan Zamazal írta:
> Lens shading correction data is represented by textures.  Let's adjust
> the signatures of eGL texture handling methods:
> 
> - Generalise createTexture2D for different formats.
> 
> - Add `const' to `data' argument to be able to accept std::array data.
> 
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
> ---
>   include/libcamera/internal/egl.h           |  8 ++++++--
>   src/libcamera/egl.cpp                      | 14 ++++++++++----
>   src/libcamera/software_isp/debayer_egl.cpp |  6 +++++-
>   3 files changed, 21 insertions(+), 7 deletions(-)
> 
> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
> index 790ec4b22..b80d65877 100644
> --- a/include/libcamera/internal/egl.h
> +++ b/include/libcamera/internal/egl.h
> @@ -107,8 +107,12 @@ public:
>   
>   	int createInputDMABufTexture2D(eGLImage &eglImage, int fd);
>   	int createOutputDMABufTexture2D(eGLImage &eglImage, int fd);
> -	void createTexture2D(eGLImage &eglImage, void *data, GLint filter);
> -	void updateTexture2D(eGLImage &eglImage, void *data);
> +	void createTexture2D(eGLImage &eglImage,
> +			     GLint internalFormat,
> +			     GLenum type,
> +			     const void *data,
> +			     GLint filter);
> +	void updateTexture2D(eGLImage &eglImage, const void *data);
>   	void createOutputTexture2D(eGLImage &eglImage);
>   
>   	int attachTextureToFBO(eGLImage &eglImage);
> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
> index 32e7e0e9c..cbae3a664 100644
> --- a/src/libcamera/egl.cpp
> +++ b/src/libcamera/egl.cpp
> @@ -277,6 +277,8 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
>   /**
>    * \brief Create a 2D texture from a memory buffer
>    * \param[in,out] eglImage EGL image to associate with the texture
> + * \param[in] internalFormat OpenGL internal storage format (e.g., GL_RGB8, GL_RGBA8)
> + * \param[in] type OpenGL pixel data type (e.g., GL_UNSIGNED_BYTE, GL_FLOAT)
>    * \param[in] data Pointer to pixel data, or nullptr for uninitialised texture
>    * \param[in] filter GL texture filter setting
>    *
> @@ -285,14 +287,18 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
>    * is useful for uploading static data like lookup tables or uniform color
>    * matrices to the GPU.
>    */
> -void eGL::createTexture2D(eGLImage &eglImage, void *data, GLint filter)
> +void eGL::createTexture2D(eGLImage &eglImage,
> +			  GLint internalFormat,
> +			  GLenum type,
> +			  const void *data,
> +			  GLint filter)
>   {
>   	ASSERT(tid_ == Thread::currentId());
>   
>   	activateBindTexture(eglImage);
>   
>   	// Generate texture, bind, associate image to texture, configure, unbind
> -	glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data);
> +	glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, eglImage.width_, eglImage.height_, 0, eglImage.format_, type, data);

Sorry, maybe I'm missing something. But where is anything other
than `GL_UNSIGNED_BYTE` used?


>   
>   	// Nearest filtering
>   	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
> @@ -338,7 +344,7 @@ EGLDisplay eGL::probeDisplay()
>    *
>    * Updates a 2D texture in VRAM.
>    */
> -void eGL::updateTexture2D(eGLImage &eglImage, void *data)
> +void eGL::updateTexture2D(eGLImage &eglImage, const void *data)
>   {
>   	ASSERT(tid_ == Thread::currentId());
>   
> @@ -357,7 +363,7 @@ void eGL::updateTexture2D(eGLImage &eglImage, void *data)
>    */
>   void eGL::createOutputTexture2D(eGLImage &eglImage)
>   {
> -	createTexture2D(eglImage, NULL, GL_NEAREST);
> +	createTexture2D(eglImage, eglImage.format_, GL_UNSIGNED_BYTE, NULL, GL_NEAREST);
>   	attachTextureToFBO(eglImage);
>   }
>   
> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
> index e03fef684..5227d2bbd 100644
> --- a/src/libcamera/software_isp/debayer_egl.cpp
> +++ b/src/libcamera/software_isp/debayer_egl.cpp
> @@ -536,7 +536,11 @@ eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona
>   		return nullptr;
>   	}
>   	if (cache_miss)
> -		egl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data(), GL_NEAREST);
> +		egl_.createTexture2D(*eglImageIn,
> +				     eglImageIn->format_,
> +				     GL_UNSIGNED_BYTE,
> +				     inMapped->value().planes()[0].data(),
> +				     GL_NEAREST);
>   	else
>   		egl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data());
>
Barnabás Pőcze Aug. 18, 2026, 10:23 a.m. UTC | #2
2026. 08. 18. 12:13 keltezéssel, Barnabás Pőcze írta:
> 2026. 08. 10. 22:19 keltezéssel, Milan Zamazal írta:
>> Lens shading correction data is represented by textures.  Let's adjust
>> the signatures of eGL texture handling methods:
>>
>> - Generalise createTexture2D for different formats.
>>
>> - Add `const' to `data' argument to be able to accept std::array data.
>>
>> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
>> ---
>>   include/libcamera/internal/egl.h           |  8 ++++++--
>>   src/libcamera/egl.cpp                      | 14 ++++++++++----
>>   src/libcamera/software_isp/debayer_egl.cpp |  6 +++++-
>>   3 files changed, 21 insertions(+), 7 deletions(-)
>>
>> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
>> index 790ec4b22..b80d65877 100644
>> --- a/include/libcamera/internal/egl.h
>> +++ b/include/libcamera/internal/egl.h
>> @@ -107,8 +107,12 @@ public:
>>       int createInputDMABufTexture2D(eGLImage &eglImage, int fd);
>>       int createOutputDMABufTexture2D(eGLImage &eglImage, int fd);
>> -    void createTexture2D(eGLImage &eglImage, void *data, GLint filter);
>> -    void updateTexture2D(eGLImage &eglImage, void *data);
>> +    void createTexture2D(eGLImage &eglImage,
>> +                 GLint internalFormat,
>> +                 GLenum type,
>> +                 const void *data,
>> +                 GLint filter);
>> +    void updateTexture2D(eGLImage &eglImage, const void *data);
>>       void createOutputTexture2D(eGLImage &eglImage);
>>       int attachTextureToFBO(eGLImage &eglImage);
>> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
>> index 32e7e0e9c..cbae3a664 100644
>> --- a/src/libcamera/egl.cpp
>> +++ b/src/libcamera/egl.cpp
>> @@ -277,6 +277,8 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
>>   /**
>>    * \brief Create a 2D texture from a memory buffer
>>    * \param[in,out] eglImage EGL image to associate with the texture
>> + * \param[in] internalFormat OpenGL internal storage format (e.g., GL_RGB8, GL_RGBA8)
>> + * \param[in] type OpenGL pixel data type (e.g., GL_UNSIGNED_BYTE, GL_FLOAT)
>>    * \param[in] data Pointer to pixel data, or nullptr for uninitialised texture
>>    * \param[in] filter GL texture filter setting
>>    *
>> @@ -285,14 +287,18 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
>>    * is useful for uploading static data like lookup tables or uniform color
>>    * matrices to the GPU.
>>    */
>> -void eGL::createTexture2D(eGLImage &eglImage, void *data, GLint filter)
>> +void eGL::createTexture2D(eGLImage &eglImage,
>> +              GLint internalFormat,
>> +              GLenum type,
>> +              const void *data,
>> +              GLint filter)
>>   {
>>       ASSERT(tid_ == Thread::currentId());
>>       activateBindTexture(eglImage);
>>       // Generate texture, bind, associate image to texture, configure, unbind
>> -    glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data);
>> +    glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, eglImage.width_, eglImage.height_, 0, eglImage.format_, type, data);
> 
> Sorry, maybe I'm missing something. But where is anything other
> than `GL_UNSIGNED_BYTE` used?

Another thing, https://docs.gl/es2/glTexImage2D says

   internalformat must match format.

and I also cannot see any place where anything other than `eGLImage::format_`
is specified. So are these new `internalFormat` and `type` parameters needed?


> 
> 
>>       // Nearest filtering
>>       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
>> @@ -338,7 +344,7 @@ EGLDisplay eGL::probeDisplay()
>>    *
>>    * Updates a 2D texture in VRAM.
>>    */
>> -void eGL::updateTexture2D(eGLImage &eglImage, void *data)
>> +void eGL::updateTexture2D(eGLImage &eglImage, const void *data)
>>   {
>>       ASSERT(tid_ == Thread::currentId());
>> @@ -357,7 +363,7 @@ void eGL::updateTexture2D(eGLImage &eglImage, void *data)
>>    */
>>   void eGL::createOutputTexture2D(eGLImage &eglImage)
>>   {
>> -    createTexture2D(eglImage, NULL, GL_NEAREST);
>> +    createTexture2D(eglImage, eglImage.format_, GL_UNSIGNED_BYTE, NULL, GL_NEAREST);
>>       attachTextureToFBO(eglImage);
>>   }
>> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
>> index e03fef684..5227d2bbd 100644
>> --- a/src/libcamera/software_isp/debayer_egl.cpp
>> +++ b/src/libcamera/software_isp/debayer_egl.cpp
>> @@ -536,7 +536,11 @@ eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona
>>           return nullptr;
>>       }
>>       if (cache_miss)
>> -        egl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data(), GL_NEAREST);
>> +        egl_.createTexture2D(*eglImageIn,
>> +                     eglImageIn->format_,
>> +                     GL_UNSIGNED_BYTE,
>> +                     inMapped->value().planes()[0].data(),
>> +                     GL_NEAREST);
>>       else
>>           egl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data());
>
Milan Zamazal Aug. 18, 2026, 2:31 p.m. UTC | #3
Barnabás Pőcze <barnabas.pocze@ideasonboard.com> writes:

> 2026. 08. 18. 12:13 keltezéssel, Barnabás Pőcze írta:
>> 2026. 08. 10. 22:19 keltezéssel, Milan Zamazal írta:
>>> Lens shading correction data is represented by textures.  Let's adjust
>>> the signatures of eGL texture handling methods:
>>>
>>> - Generalise createTexture2D for different formats.
>>>
>>> - Add `const' to `data' argument to be able to accept std::array data.
>>>
>>> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
>>> ---
>>>   include/libcamera/internal/egl.h           |  8 ++++++--
>>>   src/libcamera/egl.cpp                      | 14 ++++++++++----
>>>   src/libcamera/software_isp/debayer_egl.cpp |  6 +++++-
>>>   3 files changed, 21 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
>>> index 790ec4b22..b80d65877 100644
>>> --- a/include/libcamera/internal/egl.h
>>> +++ b/include/libcamera/internal/egl.h
>>> @@ -107,8 +107,12 @@ public:
>>>       int createInputDMABufTexture2D(eGLImage &eglImage, int fd);
>>>       int createOutputDMABufTexture2D(eGLImage &eglImage, int fd);
>>> -    void createTexture2D(eGLImage &eglImage, void *data, GLint filter);
>>> -    void updateTexture2D(eGLImage &eglImage, void *data);
>>> +    void createTexture2D(eGLImage &eglImage,
>>> +                 GLint internalFormat,
>>> +                 GLenum type,
>>> +                 const void *data,
>>> +                 GLint filter);
>>> +    void updateTexture2D(eGLImage &eglImage, const void *data);
>>>       void createOutputTexture2D(eGLImage &eglImage);
>>>       int attachTextureToFBO(eGLImage &eglImage);
>>> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
>>> index 32e7e0e9c..cbae3a664 100644
>>> --- a/src/libcamera/egl.cpp
>>> +++ b/src/libcamera/egl.cpp
>>> @@ -277,6 +277,8 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
>>>   /**
>>>    * \brief Create a 2D texture from a memory buffer
>>>    * \param[in,out] eglImage EGL image to associate with the texture
>>> + * \param[in] internalFormat OpenGL internal storage format (e.g., GL_RGB8, GL_RGBA8)
>>> + * \param[in] type OpenGL pixel data type (e.g., GL_UNSIGNED_BYTE, GL_FLOAT)
>>>    * \param[in] data Pointer to pixel data, or nullptr for uninitialised texture
>>>    * \param[in] filter GL texture filter setting
>>>    *
>>> @@ -285,14 +287,18 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
>>>    * is useful for uploading static data like lookup tables or uniform color
>>>    * matrices to the GPU.
>>>    */
>>> -void eGL::createTexture2D(eGLImage &eglImage, void *data, GLint filter)
>>> +void eGL::createTexture2D(eGLImage &eglImage,
>>> +              GLint internalFormat,
>>> +              GLenum type,
>>> +              const void *data,
>>> +              GLint filter)
>>>   {
>>>       ASSERT(tid_ == Thread::currentId());
>>>       activateBindTexture(eglImage);
>>>       // Generate texture, bind, associate image to texture, configure, unbind
>>> -    glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data);
>>> +    glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, eglImage.width_, eglImage.height_, 0, eglImage.format_, type, data);
>> Sorry, maybe I'm missing something. But where is anything other
>> than `GL_UNSIGNED_BYTE` used?
>
> Another thing, https://docs.gl/es2/glTexImage2D says
>
>   internalformat must match format.
>
> and I also cannot see any place where anything other than `eGLImage::format_`
> is specified. So are these new `internalFormat` and `type` parameters needed?

Not any more, they were needed in previous versions where floats were
used.  I wasn't sure about further type changes but those parameters are
not needed now, so I'll drop them.

>
>> 
>>>       // Nearest filtering
>>>       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
>>> @@ -338,7 +344,7 @@ EGLDisplay eGL::probeDisplay()
>>>    *
>>>    * Updates a 2D texture in VRAM.
>>>    */
>>> -void eGL::updateTexture2D(eGLImage &eglImage, void *data)
>>> +void eGL::updateTexture2D(eGLImage &eglImage, const void *data)
>>>   {
>>>       ASSERT(tid_ == Thread::currentId());
>>> @@ -357,7 +363,7 @@ void eGL::updateTexture2D(eGLImage &eglImage, void *data)
>>>    */
>>>   void eGL::createOutputTexture2D(eGLImage &eglImage)
>>>   {
>>> -    createTexture2D(eglImage, NULL, GL_NEAREST);
>>> +    createTexture2D(eglImage, eglImage.format_, GL_UNSIGNED_BYTE, NULL, GL_NEAREST);
>>>       attachTextureToFBO(eglImage);
>>>   }
>>> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
>>> index e03fef684..5227d2bbd 100644
>>> --- a/src/libcamera/software_isp/debayer_egl.cpp
>>> +++ b/src/libcamera/software_isp/debayer_egl.cpp
>>> @@ -536,7 +536,11 @@ eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona
>>>           return nullptr;
>>>       }
>>>       if (cache_miss)
>>> -        egl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data(), GL_NEAREST);
>>> +        egl_.createTexture2D(*eglImageIn,
>>> +                     eglImageIn->format_,
>>> +                     GL_UNSIGNED_BYTE,
>>> +                     inMapped->value().planes()[0].data(),
>>> +                     GL_NEAREST);
>>>       else
>>>           egl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data());
>>

Patch
diff mbox series

diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index 790ec4b22..b80d65877 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -107,8 +107,12 @@  public:
 
 	int createInputDMABufTexture2D(eGLImage &eglImage, int fd);
 	int createOutputDMABufTexture2D(eGLImage &eglImage, int fd);
-	void createTexture2D(eGLImage &eglImage, void *data, GLint filter);
-	void updateTexture2D(eGLImage &eglImage, void *data);
+	void createTexture2D(eGLImage &eglImage,
+			     GLint internalFormat,
+			     GLenum type,
+			     const void *data,
+			     GLint filter);
+	void updateTexture2D(eGLImage &eglImage, const void *data);
 	void createOutputTexture2D(eGLImage &eglImage);
 
 	int attachTextureToFBO(eGLImage &eglImage);
diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index 32e7e0e9c..cbae3a664 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -277,6 +277,8 @@  int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
 /**
  * \brief Create a 2D texture from a memory buffer
  * \param[in,out] eglImage EGL image to associate with the texture
+ * \param[in] internalFormat OpenGL internal storage format (e.g., GL_RGB8, GL_RGBA8)
+ * \param[in] type OpenGL pixel data type (e.g., GL_UNSIGNED_BYTE, GL_FLOAT)
  * \param[in] data Pointer to pixel data, or nullptr for uninitialised texture
  * \param[in] filter GL texture filter setting
  *
@@ -285,14 +287,18 @@  int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)
  * is useful for uploading static data like lookup tables or uniform color
  * matrices to the GPU.
  */
-void eGL::createTexture2D(eGLImage &eglImage, void *data, GLint filter)
+void eGL::createTexture2D(eGLImage &eglImage,
+			  GLint internalFormat,
+			  GLenum type,
+			  const void *data,
+			  GLint filter)
 {
 	ASSERT(tid_ == Thread::currentId());
 
 	activateBindTexture(eglImage);
 
 	// Generate texture, bind, associate image to texture, configure, unbind
-	glTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data);
+	glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, eglImage.width_, eglImage.height_, 0, eglImage.format_, type, data);
 
 	// Nearest filtering
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
@@ -338,7 +344,7 @@  EGLDisplay eGL::probeDisplay()
  *
  * Updates a 2D texture in VRAM.
  */
-void eGL::updateTexture2D(eGLImage &eglImage, void *data)
+void eGL::updateTexture2D(eGLImage &eglImage, const void *data)
 {
 	ASSERT(tid_ == Thread::currentId());
 
@@ -357,7 +363,7 @@  void eGL::updateTexture2D(eGLImage &eglImage, void *data)
  */
 void eGL::createOutputTexture2D(eGLImage &eglImage)
 {
-	createTexture2D(eglImage, NULL, GL_NEAREST);
+	createTexture2D(eglImage, eglImage.format_, GL_UNSIGNED_BYTE, NULL, GL_NEAREST);
 	attachTextureToFBO(eglImage);
 }
 
diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
index e03fef684..5227d2bbd 100644
--- a/src/libcamera/software_isp/debayer_egl.cpp
+++ b/src/libcamera/software_isp/debayer_egl.cpp
@@ -536,7 +536,11 @@  eGLImage *DebayerEGL::getCachedInputFrameBuffer(FrameBuffer *input, std::optiona
 		return nullptr;
 	}
 	if (cache_miss)
-		egl_.createTexture2D(*eglImageIn, inMapped->value().planes()[0].data(), GL_NEAREST);
+		egl_.createTexture2D(*eglImageIn,
+				     eglImageIn->format_,
+				     GL_UNSIGNED_BYTE,
+				     inMapped->value().planes()[0].data(),
+				     GL_NEAREST);
 	else
 		egl_.updateTexture2D(*eglImageIn, inMapped->value().planes()[0].data());