OpenGL播放yuv数据流

上传人:汽*** 文档编号:460905807 上传时间:2022-08-28 格式:DOCX 页数:14 大小:27.70KB
返回 下载 相关 举报
OpenGL播放yuv数据流_第1页
第1页 / 共14页
OpenGL播放yuv数据流_第2页
第2页 / 共14页
OpenGL播放yuv数据流_第3页
第3页 / 共14页
OpenGL播放yuv数据流_第4页
第4页 / 共14页
OpenGL播放yuv数据流_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《OpenGL播放yuv数据流》由会员分享,可在线阅读,更多相关《OpenGL播放yuv数据流(14页珍藏版)》请在金锄头文库上搜索。

1、OpenGL 播放 yuv 数据流(着色器SHADER)-IOS(一)和 windows 平台的类似,只是用 object-c 编写的,着色器语言 shader,rgb 转 yuv 有些不同 具体看代码注释。/.hcpp view plain copy 在 CODE 上查看代码片派生到我的代码片/* Copyright (c/c+) * Function* Opanal for video rendering related implementation and definition, etc.* OpanAl 用于视频渲染相关实现及定义,等*/#ifndef _LVS_OPENGL_INTE

2、RFACE_H_#define _LVS_OPENGL_INTERFACE_H_#include #import #import #import #import #import #include #include #include #include 着色器用的顶点属性索引position是由3个(x,y,z)组成,#define ATTRIB_VERTEX 3着色器用的像素,纹理属性索引而颜色是4个(r,g,b,a)#define ATTRIB_TEXTURE 4/是否旋转图像(纹理)#define TEXTURE_ROTATE0/显示图像(纹理)的一半#define TEXTURE_HALF

3、0/shader 源码用的宏#define STRINGIZE(x) #x#define STRINGIZE2(x) STRINGIZE(x)#define SHADER_STRING(text) STRINGIZE2(text)/shader 的 vsh 源码字符串/*static NSString *const vertexShaderString = SHADER_STRING(attribute vec4 position;attribute vec2 TexCoordIn;varying vec2 TexCoordOut;void main(void)gl_Position = po

4、sition;TexCoordOut = TexCoordIn;);*/static NSString *const vertexShaderString = SHADER_STRING( attribute vec4 vertexIn;attribute vec2 textureIn;varying vec2 textureOut;void main(void)gl_Position = vertexIn;textureOut = textureIn;);/shader 的 fsh 源码字符串static NSString *const yuvFragmentShaderString = S

5、HADER_STRING( varying lowp vec2 textureOut;uniform sampler2D tex_y;uniform sampler2D tex_u;uniform sampler2D tex_v;void main(void) mediump vec3 yuv; lowp vec3 rgb;yuv.x = texture2D(tex_y, textureOut).r;yuv.y = texture2D(tex_u, textureOut).r - 0.5;* yuv;yuv.z = texture2D(tex_v, textureOut).r - 0.5;rg

6、b = mat3(1,1,1,0,-0.39465,2.03211,1.13983, -0.58060, 0) gl_FragColor = vec4(rgb, 1););/*static NSString *const yuvFragmentShaderString = SHADER_STRING( varying vec2 textureOut;uniform sampler2D tex_y;uniform sampler2D tex_u;uniform sampler2D tex_v;void main(void)vec3 yuv;vec3 rgb;yuv.x = texture2D(t

7、ex_y, textureOut).r;yuv.y = texture2D(tex_u, textureOut).r - 0.5;yuv.z = texture2D(tex_v, textureOut).r - 0.5;rgb = mat3( 1, 1, 1,0, -0.39465, 2.03211,1.13983, -0.58060, 0) * yuv; gl_FragColor = vec4(rgb, 1););*/回调读取数据函数指针,数据及时间戳typedef int (*DisplayDataCK)(void * data,int * timer_millis);/接口初始化int

8、lvs_opengl_interface_init(int yuvdata_width,int yuvdata_height,DisplayDataCK displaydatack,void* pview);/接口释放void lvs_opengl_interface_uninit();/接口渲染数据(定时器,渲染时间,毫秒),数据及渲染定时时间在回调里面做处理 void lvs_opengl_interface_write(int value);/渲染数据(定时器,渲染时间,毫秒),数据及渲染定时时间在回调里面做处理void TimerFunc1(int value);/这里如果有可能则调成

9、类的成员函数,以后处理,暂时不知道怎么解决类成员函数递归?interface OpenGL_Display_Interface : UIViewpublicEAGLContext *m_eaglContext; /opengl 的 view用的context,用于OpenGL的窗口和ios的view窗口关联,很重要DisplayDataCK m_displaydatack;/用于显示回调函数,参数数据及时间戳char * m_yuvbuf;/存放 yuv 数据的 buf 指针,申请 buffer 在外面int m_millis_realtime;/实时的时间戳,每次回调会更新int m_yuv

10、data_width;/数据宽int m_yuvdata_height;privateGLuint m_frameBuffer;GLuint m_renderBuffer;GLuint m_textureid_y, m_textureid_u, m_textureid_v;/数据高/framebuffer/renderbuffer/纹理的名称,并且,该纹理的名称在当前的应用中不能被再次使用。GLuint m_textureUniformY, m_textureUniformU,m_textureUniformV; /用于纹理渲染的变量/创建用于显示的 buffer- (int)createFr

11、ameAndRenderBuffer;/删除用于显示的 buffer- (void)destoryFrameAndRenderBuffer;/初始化 - (int)initopengl: (int)yuvdata_width andyuvdata_height: (int)yuvdata_height anddisplaycallback: (DisplayDataCK)displaydatack;初始化着色器,类似于告GPU当传进去数据的时候采用什么样的规则。- (void)InitShaders;/具体显示图像的函数- (int)DisplayImage: (void*)parm;end;

12、#endif/.mmcpp view plain copy 在 CODE 上查看代码片派生到我的代码片/ Lvs_OpenGl_Interface_Ios.cpp/ LvsIos_Play/ Created by mx on 2016/12/7./ Copyright 2016 年 lvs. All rights reserved./#include Lvs_OpenGl_Interface_Ios.hstatic OpenGL_Display_Interface * copengl_interface = NULL;int lvs_opengl_interface_init(int yuvd

13、ata_width,int yuvdata_height, DisplayDataCK displaydatack,void* pview)int ret = 0; printf(lvs_opengl_interface_initn);UIImageView * ppview = (UIImageView*)pview;if (copengl_interface = NULL) copengl_interface = OpenGL_Display_Interface allocinitWithFrame:CGRectMake(0,0, ppview.frame.size.width, ppvi

14、ew.frame.size.height); ppview addSubview:copengl_interface;/初始化ret =copengl_interface initopengl:yuvdata_width andyuvdata_height: yuvdata_height anddisplaycallback: displaydatack;if (ret != 1)return -1;初始化着色器,类似于告GPU当传进去数据的时候采用什么样的规则。 copengl_interface InitShaders;ret = 1; return ret;void lvs_opengl_interface_uninit() printf(lvs_opengl_interface_uninitn);if(copengl_interface != NULL)copengl_interface destoryFrameAndRenderBuffer;copengl_interface release; copengl_interface = NUL

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 建筑资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号