RGBA和BGR的自动适配

master
a7458969 2020-05-26 11:43:06 +08:00
parent 8f9a31dc78
commit 0e3f6f3b97
2 changed files with 13 additions and 13 deletions

View File

@ -32,6 +32,7 @@ void main(void) \
gl_FragColor = vec4(rgb, 1); \ gl_FragColor = vec4(rgb, 1); \
}"; }";
// rgb片段着色器源码 // rgb片段着色器源码
// 注意MEDIASUBTYPE_RGB32 是bgr的所以需要再进行一次转换
const char *fsrcrgb = "varying vec2 textureOut; \ const char *fsrcrgb = "varying vec2 textureOut; \
uniform sampler2D rgbdata; \ uniform sampler2D rgbdata; \
void main() \ void main() \
@ -76,11 +77,12 @@ CPlayWidget::CPlayWidget(QWidget *parent):QOpenGLWidget(parent) {
m_nVideoW = 0; m_nVideoW = 0;
mType = TYPE_YUV420P; mType = TYPE_YUV420P;
connect(&this->tm,SIGNAL(timeout()),this,SLOT(OnUpdateFrame())); connect(&this->tm,SIGNAL(timeout()),this,SLOT(OnUpdateFrame()));
//tm.start(1000); //tm.start(1000);
} }
CPlayWidget::~CPlayWidget() { CPlayWidget::~CPlayWidget() {
} }
void CPlayWidget::PlayOneFrame() {//函数功能读取一张yuv图像数据进行显示,每单击一次,就显示一张图片 void CPlayWidget::PlayOneFrame() {//函数功能读取一张yuv图像数据进行显示,每单击一次,就显示一张图片
if(NULL == m_pYuvFile) if(NULL == m_pYuvFile)
{ {
@ -111,15 +113,13 @@ void CPlayWidget::PlayOneFrame() {//函数功能读取一张yuv图像数据进
return; return;
} }
int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type) int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type){
{
this->mType = type; this->mType = type;
} }
int CPlayWidget::OnCameraData(uint8_t *dat, uint32_t size) int CPlayWidget::OnCameraData(uint8_t *dat, uint32_t size)
{ {
memcpy(this->m_pBufRgb32,dat,size); memcpy(this->m_pBufRgb32,dat,size);
qDebug()<<"camera receive data"<<size<<"\r\n";
update(); update();
} }
@ -284,10 +284,10 @@ void CPlayWidget::resizeGL(int w, int h)
}; };
//纹理矩阵 //纹理矩阵
static const GLfloat textureVertices[] = { static const GLfloat textureVertices[] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
}; };
//设置属性ATTRIB_VERTEX的顶点矩阵值以及格式 //设置属性ATTRIB_VERTEX的顶点矩阵值以及格式
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices); glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices);
@ -378,7 +378,7 @@ void CPlayWidget::resizeGL(int w, int h)
m_nVideoW, m_nVideoW,
m_nVideoH, m_nVideoH,
0, 0,
GL_RGBA, GL_BGRA,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
m_pBufRgb32); m_pBufRgb32);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>878</width> <width>1208</width>
<height>732</height> <height>943</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -19,8 +19,8 @@
<rect> <rect>
<x>19</x> <x>19</x>
<y>20</y> <y>20</y>
<width>831</width> <width>1171</width>
<height>630</height> <height>851</height>
</rect> </rect>
</property> </property>
</widget> </widget>
@ -30,8 +30,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>878</width> <width>1208</width>
<height>23</height> <height>26</height>
</rect> </rect>
</property> </property>
</widget> </widget>