Skip to content

Commit

Permalink
LVGL: support all color depths for opengl builds
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed May 29, 2024
1 parent 9660ac6 commit 6c880fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 12 additions & 5 deletions generic/LVGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ struct LVGLWidget<BaseWidget>::PrivateData {

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

static constexpr const float transparent[] = { 0.f, 0.f, 0.f, 0.f };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, transparent);
Expand Down Expand Up @@ -363,13 +363,20 @@ void LVGLWidget<BaseWidget>::onDisplay()
{
#if LV_COLOR_DEPTH == 32
static constexpr const GLenum format = GL_BGRA;
static constexpr const GLenum ftype = GL_UNSIGNED_BYTE;
#elif LV_COLOR_DEPTH == 24
static constexpr const GLenum format = GL_BGR;
static constexpr const GLenum ftype = GL_UNSIGNED_BYTE;
#elif LV_COLOR_DEPTH == 16
static constexpr const GLenum format = GL_RGB;
static constexpr const GLenum ftype = GL_UNSIGNED_SHORT_5_6_5;
#elif LV_COLOR_DEPTH == 8
static constexpr const GLenum format = GL_LUMINANCE;
static constexpr const GLenum ftype = GL_UNSIGNED_BYTE;
#else
#error Unsupported color format
#endif

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, width);

Expand All @@ -379,7 +386,7 @@ void LVGLWidget<BaseWidget>::onDisplay()
lvglData->updatedArea.x2 == width &&
lvglData->updatedArea.y2 == height)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, lvglData->textureData);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, ftype, lvglData->textureData);
}
// partial size
else
Expand All @@ -397,7 +404,7 @@ void LVGLWidget<BaseWidget>::onDisplay()
partial_y,
partial_width,
partial_height,
format, GL_UNSIGNED_BYTE,
format, ftype,
lvglData->textureData + offset);
}

Expand Down
2 changes: 0 additions & 2 deletions generic/LVGL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ START_NAMESPACE_DGL

#if defined(DGL_CAIRO) && LV_COLOR_DEPTH != 32
# error LV_COLOR_DEPTH must be 32 for Cairo DPF builds
#elif LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32
# error LV_COLOR_DEPTH must be 24 or 32 for DPF builds
#endif

#if LV_DEF_REFR_PERIOD != 1
Expand Down

0 comments on commit 6c880fb

Please sign in to comment.