EGL + GBM + OPENGLES 最简实例


前言

本文主要介绍如何在 linux 下实现一个 egl + gbm + opengles 的最简demo 实例
软硬件环境
硬件:PC
软件:ubuntu18.04 egl1.4 opengles2.0 libgbm libdrm


一、GBM

  • GBM(全称是Generic Buffer Manager)是一个用于管理图形缓冲区的通用接口,主要用于在 Linux 系统上实现图形显示和渲染,是以动态库 libgbm 来进行呈现的
  • GBM 提供了一组 API,允许用户通过创建和管理缓冲区对象来与底层图形设备交互。它可以与不同的图形后端(如 DRM、EGL 和 Mesa 等)集成,以便在不同的系统中实现硬件加速图形

二、egl + gbm + opengles 最简 demo 实例

1.egl_gbm.c

egl_gbm.c 代码如下

#include <xf86drm.h>
#include <xf86drmMode.h>
#include <gbm.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
 
#define EXIT(msg) {
      fputs (msg, stderr); exit (EXIT_FAILURE); }
 
void assertEGLError(const char *msg)
{
   
    EGLint error = eglGetError();
    if(error != EGL_SUCCESS) {
   
        printf("EGL error 0x%x at %s\n", error, msg);
    }
}
 
static int g_device_fd;
 
static uint32_t connector_id;
static drmModeModeInfo mode_info;
static drmModeCrtc *crtc;
static struct gbm_device *gbm_device;
 
static EGLDisplay display;
static EGLContext context;
static struct gbm_surface *gbm_surface;
static EGLSurface egl_surface;
 
static struct gbm_bo *previous_bo = NULL;
static uint32_t previous_fb;

static void swap_buffers () {
   
	eglSwapBuffers (display, egl_surface);
	struct gbm_bo *bo = gbm_surface_lock_front_buffer (gbm_surface);
	uint32_t handle = gbm_bo_get_handle (bo).u32;
	uint32_t pitch = gbm_bo_get_stride (bo);
	uint32_t fb
  • 19
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值