mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-09 20:27:41 +08:00
feat(glfw): remove glew dependency and use glad instead (#9319)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -19,14 +19,12 @@ Getting Started with GLFW
|
||||
Prerequisites
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
The GLFW driver uses GLEW GLFW to access the OpenGL window manager.
|
||||
|
||||
1. Install GLEW and GLFW: ``sudo apt-get install libglew-dev libglfw3-dev``
|
||||
1. Install GLFW: ``sudo apt-get install libglfw3-dev``
|
||||
|
||||
Configure GLFW Driver
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
1. Required linked libraries: -lGL -lGLEW -lglfw
|
||||
1. Required linked libraries: -lGL -lglfw
|
||||
2. Enable the OpenGL driver support in lv_conf.h, by cmake compiler define or by KConfig
|
||||
|
||||
.. code-block:: c
|
||||
@@ -92,7 +90,6 @@ used to add content to a texture and the driver will draw the texture in the win
|
||||
.. code-block:: c
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define WIDTH 640
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
vcpkg install vcpkg-tool-ninja libpng freetype opengl glfw3 glew
|
||||
vcpkg install vcpkg-tool-ninja libpng freetype opengl glfw3
|
||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
pip install pypng lz4 kconfiglib
|
||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
@@ -7,7 +7,6 @@ libpng-dev
|
||||
libjpeg-turbo8-dev
|
||||
libwebp-dev
|
||||
libfreetype-dev
|
||||
libglew-dev
|
||||
libglfw3-dev
|
||||
libsdl2-dev
|
||||
libpng-dev:i386
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
# glad
|
||||
|
||||
GLAD source files are generated using GLAD's online generator.
|
||||
[Permalink](https://gen.glad.sh/#generator=c&api=egl%3D1.5%2Cgles2%3D2.0&profile=gl%3Dcompatibility%2Cgles1%3Dcommon&extensions=EGL_EXT_image_dma_buf_import%2CEGL_EXT_image_dma_buf_import_modifiers%2CEGL_EXT_platform_base%2CEGL_EXT_platform_wayland%2CEGL_KHR_fence_sync%2CEGL_KHR_image_base%2CEGL_KHR_platform_gbm%2CEGL_KHR_platform_wayland%2CGL_APPLE_texture_max_level%2CGL_ARM_rgba8%2CGL_EXT_color_buffer_float%2CGL_EXT_color_buffer_half_float%2CGL_EXT_texture_format_BGRA8888%2CGL_EXT_texture_storage%2CGL_EXT_unpack_subimage%2CGL_OES_depth24%2CGL_OES_mapbuffer%2CGL_OES_rgb8_rgba8%2CGL_OES_texture_float%2CGL_OES_texture_half_float%2CGL_OES_texture_storage_multisample_2d_array%2CGL_OES_vertex_array_object&options=ALIAS)
|
||||
|
||||
[Permalink](https://gen.glad.sh/#generator=c&api=egl%3D1.5%2Cgl%3D3.3%2Cgles2%3D2.0&profile=gl%3Dcompatibility%2Cgles1%3Dcommon&extensions=EGL_EXT_image_dma_buf_import%2CEGL_EXT_image_dma_buf_import_modifiers%2CEGL_EXT_platform_base%2CEGL_EXT_platform_wayland%2CEGL_KHR_fence_sync%2CEGL_KHR_image_base%2CEGL_KHR_platform_gbm%2CGL_APPLE_texture_max_level%2CGL_ARM_rgba8%2CGL_EXT_color_buffer_float%2CGL_EXT_color_buffer_half_float%2CGL_EXT_texture_format_BGRA8888%2CGL_EXT_texture_storage%2CGL_EXT_unpack_subimage%2CGL_OES_depth24%2CGL_OES_mapbuffer%2CGL_OES_rgb8_rgba8%2CGL_OES_texture_float%2CGL_OES_texture_half_float%2CGL_OES_texture_storage_multisample_2d_array%2CGL_OES_vertex_array_object&options=ALIAS%2CALIAS)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#ifndef __eglplatform_h_
|
||||
#define __eglplatform_h_
|
||||
|
||||
#include "../../../lv_opengles_egl.h"
|
||||
|
||||
#if LV_USE_EGL
|
||||
#include "../../../../../lv_conf_internal.h"
|
||||
#if LV_USE_OPENGLES
|
||||
|
||||
/*
|
||||
** Copyright 2007-2020 The Khronos Group Inc.
|
||||
@@ -176,6 +175,5 @@ typedef khronos_int32_t EGLint;
|
||||
#define EGL_CAST(type, value) ((type) (value))
|
||||
#endif
|
||||
|
||||
#endif /*LV_USE_EGL*/
|
||||
|
||||
#endif /*LV_USE_OPENGLES*/
|
||||
#endif /* __eglplatform_h */
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
#include "../../../lv_opengles_egl.h"
|
||||
|
||||
#if LV_USE_EGL
|
||||
|
||||
#include "../../../../../lv_conf_internal.h"
|
||||
#if LV_USE_OPENGLES
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
@@ -312,6 +310,5 @@ typedef enum {
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* LV_USE_EGL */
|
||||
|
||||
#endif /*LV_USE_OPENGLES*/
|
||||
#endif /* __khrplatform_h_ */
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Loader generated by glad 2.0.8 on Tue Sep 30 16:40:42 2025
|
||||
* Loader generated by glad 2.0.8 on Fri Nov 28 10:05:15 2025
|
||||
*
|
||||
* SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0
|
||||
*
|
||||
* Generator: C/C++
|
||||
* Specification: egl
|
||||
* Extensions: 11
|
||||
* Extensions: 10
|
||||
*
|
||||
* APIs:
|
||||
* - egl=1.5
|
||||
@@ -19,18 +19,18 @@
|
||||
* - ON_DEMAND = False
|
||||
*
|
||||
* Commandline:
|
||||
* --api='egl=1.5' --extensions='EGL_EXT_image_dma_buf_import,EGL_EXT_image_dma_buf_import_modifiers,EGL_EXT_platform_base,EGL_EXT_platform_wayland,EGL_KHR_cl_event2,EGL_KHR_fence_sync,EGL_KHR_image,EGL_KHR_image_base,EGL_KHR_platform_gbm,EGL_KHR_platform_wayland,EGL_KHR_reusable_sync' c --alias
|
||||
* --api='egl=1.5' --extensions='EGL_EXT_image_dma_buf_import,EGL_EXT_image_dma_buf_import_modifiers,EGL_EXT_platform_base,EGL_EXT_platform_wayland,EGL_KHR_cl_event2,EGL_KHR_fence_sync,EGL_KHR_image,EGL_KHR_image_base,EGL_KHR_platform_gbm,EGL_KHR_reusable_sync' c --alias
|
||||
*
|
||||
* Online:
|
||||
* http://glad.sh/#api=egl%3D1.5&extensions=EGL_EXT_image_dma_buf_import%2CEGL_EXT_image_dma_buf_import_modifiers%2CEGL_EXT_platform_base%2CEGL_EXT_platform_wayland%2CEGL_KHR_cl_event2%2CEGL_KHR_fence_sync%2CEGL_KHR_image%2CEGL_KHR_image_base%2CEGL_KHR_platform_gbm%2CEGL_KHR_platform_wayland%2CEGL_KHR_reusable_sync&generator=c&options=ALIAS
|
||||
* http://glad.sh/#api=egl%3D1.5&extensions=EGL_EXT_image_dma_buf_import%2CEGL_EXT_image_dma_buf_import_modifiers%2CEGL_EXT_platform_base%2CEGL_EXT_platform_wayland%2CEGL_KHR_cl_event2%2CEGL_KHR_fence_sync%2CEGL_KHR_image%2CEGL_KHR_image_base%2CEGL_KHR_platform_gbm%2CEGL_KHR_reusable_sync&generator=c&options=ALIAS
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GLAD_EGL_H_
|
||||
#define GLAD_EGL_H_
|
||||
|
||||
#include "../../../lv_opengles_egl.h"
|
||||
|
||||
#include "../../../../../lv_conf_internal.h"
|
||||
#if LV_USE_EGL
|
||||
|
||||
#define GLAD_EGL
|
||||
@@ -470,8 +470,6 @@ GLAD_API_CALL int GLAD_EGL_KHR_image;
|
||||
GLAD_API_CALL int GLAD_EGL_KHR_image_base;
|
||||
#define EGL_KHR_platform_gbm 1
|
||||
GLAD_API_CALL int GLAD_EGL_KHR_platform_gbm;
|
||||
#define EGL_KHR_platform_wayland 1
|
||||
GLAD_API_CALL int GLAD_EGL_KHR_platform_wayland;
|
||||
#define EGL_KHR_reusable_sync 1
|
||||
GLAD_API_CALL int GLAD_EGL_KHR_reusable_sync;
|
||||
|
||||
@@ -660,6 +658,6 @@ GLAD_API_CALL int gladLoadEGL(EGLDisplay display, GLADloadfunc load);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*LV_USE_EGL*/
|
||||
|
||||
#endif /*LV_USE_EGL*/
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Loader generated by glad 2.0.8 on Tue Sep 30 16:40:43 2025
|
||||
* Loader generated by glad 2.0.8 on Fri Nov 28 10:05:18 2025
|
||||
*
|
||||
* SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0
|
||||
*
|
||||
@@ -29,8 +29,7 @@
|
||||
#ifndef GLAD_GLES2_H_
|
||||
#define GLAD_GLES2_H_
|
||||
|
||||
#include "../../../lv_opengles_egl.h"
|
||||
|
||||
#include "../../../../../lv_conf_internal.h"
|
||||
#if LV_USE_EGL
|
||||
|
||||
#ifdef __clang__
|
||||
@@ -1106,6 +1105,6 @@ GLAD_API_CALL int gladLoadGLES2( GLADloadfunc load);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*LV_USE_EGL*/
|
||||
|
||||
#endif /*LV_USE_EGL*/
|
||||
#endif
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
* SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0
|
||||
*/
|
||||
|
||||
#include "../../lv_opengles_egl.h"
|
||||
|
||||
#include "../../lv_opengles_private.h"
|
||||
#if LV_USE_EGL
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -43,7 +41,6 @@ int GLAD_EGL_KHR_fence_sync = 0;
|
||||
int GLAD_EGL_KHR_image = 0;
|
||||
int GLAD_EGL_KHR_image_base = 0;
|
||||
int GLAD_EGL_KHR_platform_gbm = 0;
|
||||
int GLAD_EGL_KHR_platform_wayland = 0;
|
||||
int GLAD_EGL_KHR_reusable_sync = 0;
|
||||
|
||||
|
||||
@@ -262,7 +259,6 @@ static int glad_egl_find_extensions_egl(EGLDisplay display) {
|
||||
GLAD_EGL_KHR_image = glad_egl_has_extension(extensions, "EGL_KHR_image");
|
||||
GLAD_EGL_KHR_image_base = glad_egl_has_extension(extensions, "EGL_KHR_image_base");
|
||||
GLAD_EGL_KHR_platform_gbm = glad_egl_has_extension(extensions, "EGL_KHR_platform_gbm");
|
||||
GLAD_EGL_KHR_platform_wayland = glad_egl_has_extension(extensions, "EGL_KHR_platform_wayland");
|
||||
GLAD_EGL_KHR_reusable_sync = glad_egl_has_extension(extensions, "EGL_KHR_reusable_sync");
|
||||
|
||||
return 1;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0
|
||||
*/
|
||||
#include "../../lv_opengles_egl.h"
|
||||
|
||||
#include "../../lv_opengles_private.h"
|
||||
|
||||
#if LV_USE_EGL
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ static uint32_t lv_glfw_tick_count_callback(void);
|
||||
static lv_opengles_window_t * lv_glfw_get_lv_window_from_window(GLFWwindow * window);
|
||||
static void glfw_error_cb(int error, const char * description);
|
||||
static int lv_glfw_init(void);
|
||||
static int lv_glew_init(void);
|
||||
static lv_result_t lv_glad_init(void);
|
||||
static void lv_glfw_timer_init(void);
|
||||
static void lv_glfw_window_config(GLFWwindow * window, bool use_mouse_indev);
|
||||
static void lv_glfw_window_quit(void);
|
||||
@@ -89,7 +89,7 @@ static void window_display_flush_cb(lv_display_t * disp, const lv_area_t * area,
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static bool glfw_inited;
|
||||
static bool glew_inited;
|
||||
static bool glad_inited;
|
||||
static lv_timer_t * update_handler_timer;
|
||||
static lv_ll_t glfw_window_ll;
|
||||
#if !LV_USE_DRAW_OPENGLES
|
||||
@@ -149,7 +149,16 @@ lv_opengles_window_t * lv_opengles_glfw_window_create_ex(int32_t hor_res, int32_
|
||||
glfwSetWindowUserPointer(window->window, window);
|
||||
lv_glfw_timer_init();
|
||||
lv_glfw_window_config(window->window, use_mouse_indev);
|
||||
lv_glew_init();
|
||||
|
||||
lv_result_t res = lv_glad_init();
|
||||
if(res != LV_RESULT_OK) {
|
||||
LV_LOG_ERROR("Failed to init glad");
|
||||
glfwDestroyWindow(window->window);
|
||||
lv_ll_remove(&glfw_window_ll, window);
|
||||
lv_free(window);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window->window);
|
||||
lv_opengles_init();
|
||||
|
||||
@@ -384,24 +393,24 @@ static int lv_glfw_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lv_glew_init(void)
|
||||
static lv_result_t lv_glad_init(void)
|
||||
{
|
||||
if(glew_inited) {
|
||||
return 0;
|
||||
if(glad_inited) {
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
|
||||
GLenum ret = glewInit();
|
||||
if(ret != GLEW_OK) {
|
||||
LV_LOG_ERROR("glewInit fail: %d.", ret);
|
||||
return ret;
|
||||
|
||||
if(!gladLoadGL((GLADloadfunc)glfwGetProcAddress)) {
|
||||
LV_LOG_ERROR("Failed to load OpenGL functions");
|
||||
return LV_RESULT_INVALID;
|
||||
}
|
||||
|
||||
LV_LOG_INFO("GL version: %s", glGetString(GL_VERSION));
|
||||
LV_LOG_INFO("GLSL version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
||||
glew_inited = true;
|
||||
glad_inited = true;
|
||||
|
||||
return 0;
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
|
||||
static void lv_glfw_timer_init(void)
|
||||
@@ -513,7 +522,7 @@ static void window_update_handler(lv_timer_t * t)
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, lv_area_get_width(&texture->area), lv_area_get_height(&texture->area), 0,
|
||||
GL_RED, GL_UNSIGNED_BYTE, texture->fb));
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, lv_area_get_width(&texture->area), lv_area_get_height(&texture->area),
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, lv_area_get_width(&texture->area), lv_area_get_height(&texture->area),
|
||||
0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
|
||||
texture->fb));
|
||||
#elif LV_COLOR_DEPTH == 24
|
||||
|
||||
@@ -15,6 +15,7 @@ extern "C" {
|
||||
*********************/
|
||||
|
||||
#include "../../lv_conf_internal.h"
|
||||
|
||||
#if LV_USE_OPENGLES
|
||||
|
||||
#include "../../misc/lv_area.h"
|
||||
@@ -24,12 +25,13 @@ extern "C" {
|
||||
#include "glad/include/glad/gles2.h"
|
||||
#include "glad/include/glad/egl.h"
|
||||
#else
|
||||
/* For now, by default we add glew and glfw.
|
||||
In the future we need to consider adding a config for setting these includes*/
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "glad/include/glad/gl.h"
|
||||
#endif /*LV_USE_EGL*/
|
||||
|
||||
#if LV_USE_GLFW
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
@@ -205,7 +205,7 @@ static unsigned int create_texture(int32_t w, int32_t h)
|
||||
/* set the dimensions and format to complete the texture */
|
||||
/* Color depth: 16 (RGB565), 32 (XRGB8888) */
|
||||
#if LV_COLOR_DEPTH == 16
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
|
||||
NULL));
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
|
||||
@@ -248,7 +248,7 @@ static void flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * px_m
|
||||
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / lv_color_format_get_size(cf)));
|
||||
/*Color depth: 16 (RGB565), 32 (XRGB8888)*/
|
||||
#if LV_COLOR_DEPTH == 16
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, disp->hor_res, disp->ver_res, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, disp->hor_res, disp->ver_res, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
|
||||
dsc->fb1));
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, disp->hor_res, disp->ver_res, 0, GL_RGBA, GL_UNSIGNED_BYTE, dsc->fb1));
|
||||
|
||||
@@ -416,21 +416,19 @@ endif()
|
||||
|
||||
# OpenGL ES is required for its driver
|
||||
if ($ENV{NON_AMD64_BUILD})
|
||||
message("Disable OpenGL, GLEW or glfw3 for non-amd64 build")
|
||||
message("Disable OpenGL, glfw3 for non-amd64 build")
|
||||
add_definitions(-DLV_USE_OPENGLES=0)
|
||||
else()
|
||||
find_package(OpenGL)
|
||||
find_package(GLEW)
|
||||
find_package(glfw3)
|
||||
|
||||
if(OpenGL_FOUND AND GLEW_FOUND AND glfw3_FOUND)
|
||||
if(OpenGL_FOUND AND glfw3_FOUND)
|
||||
# Include directories
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
include_directories(${GLEW_INCLUDE_DIRS})
|
||||
include_directories(${GLFW_INCLUDE_DIRS})
|
||||
message("Enable LV_USE_OPENGLES")
|
||||
else()
|
||||
message("OpenGL, GLEW or glfw3 not found, defaulting to 0")
|
||||
message("OpenGL, glfw3 not found, defaulting to 0")
|
||||
add_definitions(-DLV_USE_OPENGLES=0)
|
||||
endif()
|
||||
endif()
|
||||
@@ -534,7 +532,7 @@ foreach( test_case_fname ${TEST_CASE_FILES} )
|
||||
|
||||
if (NOT $ENV{NON_AMD64_BUILD})
|
||||
target_link_libraries(${test_name} PRIVATE
|
||||
${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} glfw)
|
||||
${OPENGL_LIBRARIES} glfw)
|
||||
endif()
|
||||
|
||||
target_include_directories(${test_name} PUBLIC ${TEST_INCLUDE_DIRS})
|
||||
|
||||
Reference in New Issue
Block a user