package com.xiaxl.selector.demo.egl;
import android.graphics.SurfaceTexture;
import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLSurface;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.xiaxl.selector.demo.egl.utils.EGLLog;
/**
* EGL 相关配置
* @author xiaxveliang@163.com
* @since 2022/04/06
*/
public class EGLDisplayHelper {
private static final String TAG = EGLDisplayHelper.class.getSimpleName();
//
private static final int EGL_RECORDABLE_ANDROID = 0x3142;
//
private EGLContext mEglContext = EGL14.EGL_NO_CONTEXT;
private EGLDisplay mEglDisplay = EGL14.EGL_NO_DISPLAY;
private EGLSurface mEglSurface = EGL14.EGL_NO_SURFACE;
/**
* 构造方法
*
* @param inEglContext
*/
public EGLDisplayHelper(final EGLContext inEglContext, final Object inSurface) {
init(inEglContext, inSurface);
}
/**
* 初始化EGL
*
* @param inEglContext
*/
private void init(final EGLContext inEglContext, final Object inSurface) {
if (!(inSurface instanceof SurfaceView)
&& !(inSurface instanceof Surface)
&& !(inSurface instanceof SurfaceHolder)
&& !(inSurface instanceof SurfaceTexture)) {
throw new IllegalArgumentException("unsupported surface");
}
//--------------------mEGLDisplay-----------------------
// EGL Display
if (mEglDisplay != EGL14.EGL_NO_DISPLAY) {
throw new RuntimeException("EGL already set up");
}
//
mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
if (mEglDisplay == EGL14.EGL_NO_DISPLAY) {
throw new RuntimeException("unable to get EGL14 display");
}
// 初始化
final int[] version = new int[2];
if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) {
mEglDisplay = null;
throw new RuntimeException("eglInitialize failed");
}
//--------------------mEglConfig-----------------------
// Configure EGL for recording and OpenGL ES 2.0.
int[] attribList = {
EGL14.EGL_RED_SIZE, 8,
EGL14.EGL_GREEN_SIZE, 8,
EGL14.EGL_BLUE_SIZE, 8,
EGL14.EGL_ALPHA_SIZE, 8,
//
EGL14.EGL_RENDERABLE_TYPE,
EGL14.EGL_OPENGL_ES2_BIT,
// 录制android
EGL_RECORDABLE_ANDROID,
1,
EGL14.EGL_NONE
};
EGLConfig[] configs = new EGLConfig[1];
int[] numConfigs = new int[1];
EGL14.eglChooseConfig(mEglDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0);
if (configs[0] == null) {
throw new RuntimeException("chooseConfig failed");
}
//--------------------mEglContext-----------------------
EGLContext shareEglContext = inEglContext;
if (shareEglContext == null) {
shareEglContext = EGL14.EGL_NO_CONTEXT;
}
//
final int[] attrib_list = {
EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
EGL14.EGL_NONE
};
// eglDisplay 即是之前创建的显示设备,
// share_context 指定一个共享的EGL Context,共享后,2个EGLContext可以相互使用对方创建的 texture 等资源,默认情况下是不共享的
mEglContext = EGL14.eglCreateContext(mEglDisplay, configs[0], shareEglContext, attrib_list, 0);
checkMyEGLError("eglCreateContext");
//-------------------------mEglSurface-------------------------
//
final int[] surfaceAttribs = {
EGL14.EGL_NONE
};
//
try {
EGLLog.d(TAG, "eglCreateWindowSurface.inSurface: " + inSurface);
boolean surfaceFlag = (inSurface instanceof Surface);
EGLLog.d(TAG, "eglCreateWindowSurface.inSurface instanceof Surface: " + surfaceFlag);
mEglSurface = EGL14.eglCreateWindowSurface(mEglDisplay, configs[0], inSurface, surfaceAttribs, 0);
} catch (final IllegalArgumentException e) {
e.printStackTrace();
EGLLog.e(TAG,"eglCreateWindowSurface", e);
}
//-----------------------------
makeEGLCurrentDisplay();
}
/**
* change context to draw this window surface
*
* @return
*/
private boolean makeEGLCurrentDisplay() {
//
if (mEglDisplay == null) {
EGLLog.e(TAG, "mEglDisplay == null");
return false;
}
if (mEglSurface == null || mEglSurface == EGL14.EGL_NO_SURFACE) {
final int error = EGL14.eglGetError();
if (error == EGL14.EGL_BAD_NATIVE_WINDOW) {
EGLLog.e(TAG, "makeMyEGLCurrentSurface:returned EGL_BAD_NATIVE_WINDOW.");
}
return false;
}
// EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx
if (!EGL14.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
Log.w(TAG, "eglMakeCurrent:" + EGL14.eglGetError());
return false;
}
return true;
}
/**
* 交换buffer数据
*
* @return
*/
public int swapEGLBuffers() {
//
boolean result = EGL14.eglSwapBuffers(mEglDisplay, mEglSurface);
//
if (!result) {
final int err = EGL14.eglGetError();
return err;
}
//
return EGL14.EGL_SUCCESS;
}
public EGLContext getEglContext() {
return mEglContext;
}
/**
* 释放资源
*/
public void release() {
// -------mEglSurface----------
EGL14.eglMakeCurrent(mEglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
EGL14.eglDestroySurface(mEglDisplay, mEglSurface);
// -------mEglContext----------
EGL14.eglDestroyContext(mEglDisplay, mEglContext);
EGL14.eglTerminate(mEglDisplay);
EGL14.eglReleaseThread();
//
mEglSurface = EGL14.EGL_NO_SURFACE;
mEglDisplay = EGL14.EGL_NO_DISPLAY;
mEglContext = EGL14.EGL_NO_CONTEXT;
}
/**
* 查错
*
* @param msg
*/
private void checkMyEGLError(final String msg) {
int error;
if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) {
throw new RuntimeException(msg + ": EGL error: 0x" + Integer.toHexString(error));
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android平台OpenGLES3将GL-TEXTURE-2D纹理id渲染到ImageReader提供的Surface上
共89个文件
xml:24个
webp:10个
ds_store:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 4 下载量 136 浏览量
2023-06-28
15:04:54
上传
评论
收藏 879KB ZIP 举报
温馨提示
效果目的: Android平台 将 GL_TEXTURE_2D纹理 渲染到 Surface 上 案例实现文章介绍: https://xiaxl.blog.csdn.net/article/details/131682521 技术实现流程大致如下: 1、OpenGLES3中加载GL_TEXTURE_2D纹理,生成纹理ID; 2、通过EGL构建EGLDisplay虚拟屏幕,并绑定ImageReader提供的Surface; 3、在EGL线程中,渲染GL_TEXTURE_2D对应的纹理图形; 4、在EGL线程中,完成渲染后,通过eglSwapBuffers方法交换缓冲数据; 5、在ImageReader中onImageAvailable方法中读取surface数据,保存为一张Bitmap; 6、将 步骤5 的Bitmap显示到ImageView上(用于验证纹理ID是否正常写入到Surface) 因实现流程较为复杂,技术难度要求较高,研究此案例代码花费时间较多,付费下载,谢谢。
资源推荐
资源详情
资源评论
收起资源包目录
GLES3TextureId2Surface.zip (89个子文件)
GLES3TextureId2Surface
.gradle
buildOutputCleanup
cache.properties 49B
buildOutputCleanup.lock 17B
outputFiles.bin 21KB
7.5
fileChanges
last-build.bin 1B
checksums
sha1-checksums.bin 18KB
checksums.lock 17B
executionHistory
executionHistory.bin 1.18MB
executionHistory.lock 17B
dependencies-accessors
gc.properties 0B
dependencies-accessors.lock 17B
fileHashes
fileHashes.lock 17B
resourceHashesCache.bin 19KB
fileHashes.bin 76KB
gc.properties 0B
vcsMetadata
vcs-1
gc.properties 0B
file-system.probe 8B
gradle.properties 1KB
.DS_Store 6KB
gradle
wrapper
gradle-wrapper.jar 58KB
gradle-wrapper.properties 230B
app
.DS_Store 6KB
src
main
.DS_Store 6KB
java
com
xiaxl
selector
.DS_Store 6KB
demo
.DS_Store 8KB
MySurfaceView.java 3KB
MyActivity.java 5KB
egl
.DS_Store 6KB
sprite
EGLTextureRect.java 6KB
utils
EGLShaderUtils.java 4KB
EGLLog.java 3KB
EGLVirtualDisplay.java 4KB
EGLDisplayHelper.java 7KB
gl
.DS_Store 6KB
GLTextureRect.java 6KB
GlTextureUtil.java 2KB
GLShaderUtils.java 4KB
res
mipmap-xxhdpi
ic_launcher_round.webp 6KB
ic_launcher.webp 3KB
.DS_Store 6KB
mipmap-hdpi
ic_launcher_round.webp 3KB
ic_launcher.webp 1KB
drawable-nodpi
.DS_Store 6KB
rect_pic.png 519KB
icon.png 3KB
navigation
nav_graph.xml 1KB
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-anydpi-v26
ic_launcher.xml 272B
ic_launcher_round.xml 272B
values-land
dimens.xml 66B
menu
menu_main.xml 411B
values-w600dp
dimens.xml 66B
values-night
themes.xml 814B
mipmap-mdpi
ic_launcher_round.webp 2KB
ic_launcher.webp 982B
mipmap-xxxhdpi
ic_launcher_round.webp 8KB
ic_launcher.webp 4KB
mipmap-xhdpi
ic_launcher_round.webp 4KB
ic_launcher.webp 2KB
mipmap-anydpi-v33
ic_launcher.xml 343B
xml
data_extraction_rules.xml 551B
backup_rules.xml 478B
values
dimens.xml 66B
colors.xml 378B
strings.xml 560B
themes.xml 1KB
layout
activity_main.xml 769B
activity_my.xml 795B
drawable
.DS_Store 6KB
ic_launcher_background.xml 5KB
values-w1240dp
dimens.xml 67B
AndroidManifest.xml 997B
proguard-rules.pro 750B
libs
build.gradle 1KB
.gitignore 6B
gradlew.bat 3KB
build.gradle 229B
.idea
modules
app
GLES3_Texture2Surface.app.androidTest.iml 164B
GLES3_FOB.app.unitTest.iml 152B
GLES3_Texture2Surface.app.unitTest.iml 164B
GLES3_FOB.app.androidTest.iml 152B
workspace.xml 6KB
misc.xml 468B
compiler.xml 169B
gradle.xml 680B
.gitignore 47B
settings.gradle 295B
local.properties 440B
gradlew 6KB
.gitignore 232B
共 89 条
- 1
资源评论
- whuthj2023-09-15总算找到了想要的资源,搞定遇到的大问题,赞赞赞!
- _Track2023-10-26怎么能有这么好的资源!只能用感激涕零来形容TAT...
- ll_zhao20232024-01-09资源很好用,有较大的参考价值,资源不错,支持一下。
- chengtingfei2024-03-13非常有用的资源,可以直接使用,对我很有用,果断支持!
bjxiaxueliang
- 粉丝: 1w+
- 资源: 47
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- YOLOV4-TINY权重文件
- 以下是一个使用贪心算法解决多机调度问题的基本步骤0.txt
- 基于大数据的房产估价是近年来随着技术的发展而兴起的一种新型估价方法.txt
- 企业供应链管理系统v3.rar
- 富芮坤FR8016HA蓝牙开发板使用手册+硬件PCB图+封装库+DEMO演示软件源代码.zip
- 基于YOLOv7的芯片表面缺陷检测系统
- 京东物流 数字化供应链综合研究报告2018.rar
- 基于YOLOv7的植物虫害识别&防治系统
- 2000.1-2023.8中国经济政策不确定性指数月度数据.xlsx
- Screenshot_2024-04-21-20-42-15-443_com.tencent.mm.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功