qt_rtmp_demo/cplaywidget.cpp

423 lines
12 KiB
C++
Raw Normal View History

2023-11-12 16:13:24 +00:00
#include "CPlayWidget.h"
#include <QOpenGLTexture>
#include <QOpenGLBuffer>
#include <QMouseEvent>
#include "CPlayWidget.h"
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Դ<EFBFBD><D4B4>
const char *vsrcyuv = "attribute vec4 vertexIn; \
attribute vec2 textureIn; \
varying vec2 textureOut; \
void main(void) \
{ \
gl_Position = vertexIn; \
textureOut = textureIn; \
}";
// Ƭ<><C6AC><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Դ<EFBFBD><D4B4>
const char *fsrcyuv = "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(tex_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); \
}";
// rgbƬ<62><C6AC><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Դ<EFBFBD><D4B4>
// ע<><D7A2>MEDIASUBTYPE_RGB32 <20><>bgr<67>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ٽ<EFBFBD><D9BD><EFBFBD>һ<EFBFBD><D2BB>ת<EFBFBD><D7AA>
const char *fsrcrgb = "varying vec2 textureOut; \
uniform sampler2D rgbdata; \
void main() \
{ \
gl_FragColor = texture(rgbdata, textureOut); \
}";
void CPlayWidget::OnUpdateFrame() {
this->PlayOneFrame();
}
void CPlayWidget::OnPaintData(const uint8_t *data, uint32_t len)
{
if(nullptr == m_pBufYuv420p)
{
m_pBufYuv420p = new unsigned char[len];
qDebug("CPlayWidget::PlayOneFrame new data memory. Len=%d width=%d height=%d\n",
len, m_nVideoW, m_nVideoW);
memcpy(m_pBufYuv420p, data,len);
//ˢ<>½<EFBFBD><C2BD><EFBFBD>,<2C><><EFBFBD><EFBFBD>paintGL<47>ӿ<EFBFBD>
update();
}
}
CPlayWidget::CPlayWidget(QWidget *parent):QOpenGLWidget(parent) {
textureUniformY = 0;
textureUniformU = 0;
textureUniformV = 0;
id_y = 0;
id_u = 0;
id_v = 0;
m_pTextureRGB = nullptr;
m_pBufYuv420p = nullptr;
m_pVSHader = NULL;
m_pFSHader = NULL;
m_pShaderProgram = NULL;
m_pTextureY = NULL;
m_pTextureU = NULL;
m_pTextureV = NULL;
m_pYuvFile = NULL;
m_nVideoH = 0;
m_nVideoW = 0;
mType = TYPE_YUV420P;
connect(&this->tm,SIGNAL(timeout()),this,SLOT(OnUpdateFrame()));
//tm.start(1000);
}
CPlayWidget::~CPlayWidget() {
}
void CPlayWidget::PlayOneFrame() {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>ȡһ<C8A1><D2BB>yuvͼ<76><CDBC><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD>ʾ,ÿ<><C3BF><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD><EFBFBD>ʾһ<CABE><D2BB>ͼƬ
if(NULL == m_pYuvFile)
{
//<2F><><EFBFBD><EFBFBD>yuv<75><76>Ƶ<EFBFBD>ļ<EFBFBD> ע<><D7A2><EFBFBD>޸<EFBFBD><DEB8>ļ<EFBFBD>·<EFBFBD><C2B7>
// m_pYuvFile = fopen("F://OpenglYuvDemo//1920_1080.yuv", "rb");
m_pYuvFile = fopen("F://md_sample_sp420_1080p.yuv", "rb");
//<2F><><EFBFBD><EFBFBD>yuv<75><76>Ƶ<EFBFBD><C6B5><EFBFBD>ݵķֱ<C4B7><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>,demo<6D><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1080p<30><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD>Ҫע<D2AA><D7A2><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>ݷֱ<DDB7><D6B1>ʶ<EFBFBD>Ӧ<EFBFBD><D3A6>
// m_nVideoW = 1920;
// m_nVideoH = 1080;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>һ֡yuvͼ<76><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>СΪ<D0A1>ֱ<EFBFBD><D6B1>ʵ<EFBFBD>1.5<EFBFBD><EFBFBD>
int nLen = m_nVideoW*m_nVideoH*3/2;
if(nullptr == m_pBufYuv420p)
{
m_pBufYuv420p = new unsigned char[nLen];
qDebug("CPlayWidget::PlayOneFrame new data memory. Len=%d width=%d height=%d\n",
nLen, m_nVideoW, m_nVideoW);
}
//<2F><>һ֡yuvͼ<76><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>
if(NULL == m_pYuvFile)
{
qFatal("read yuv file err.may be path is wrong!\n");
return;
}
fread(m_pBufYuv420p, 1, nLen, m_pYuvFile);
//ˢ<>½<EFBFBD><C2BD><EFBFBD>,<2C><><EFBFBD><EFBFBD>paintGL<47>ӿ<EFBFBD>
update();
return;
}
int CPlayWidget::SetDataType(CPlayWidget::IMG_TYPE type){
this->mType = type;
return 0;
}
int CPlayWidget::OnCameraData(uint8_t *dat, uint32_t size)
{
memcpy(this->m_pBufRgb32,dat,size);
update();
return 0;
}
int CPlayWidget::SetImgSize(uint32_t width, uint32_t height)
{
m_nVideoH = height;
m_nVideoW = width;
if(mType == TYPE_RGB32){
m_pBufRgb32 = new uint8_t[width * height *4];
}
if(mType == TYPE_YUV420P){
m_pBufYuv420p = new uint8_t[width * height *3/2];
}
return 0;
}
/*
* Y = 0.299 R + 0.587 G + 0.114 B
U = - 0.1687 R - 0.3313 G + 0.5 B + 128
V = 0.5 R - 0.4187 G - 0.0813 B + 128
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RGB Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>Ӵ<EFBFBD>YUV (256<EFBFBD><EFBFBD><EFBFBD><EFBFBD>) <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
R = Y + 1.402 (Cr-128)
G = Y - 0.34414 (Cb-128) - 0.71414 (Cr-128)
B = Y + 1.772 (Cb-128)
*/
void CPlayWidget::initializeGL()
{
initializeOpenGLFunctions();
glEnable(GL_DEPTH_TEST);
//<2F>ִ<EFBFBD>opengl<67><6C>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>openGL<47><4C>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>(OpenGL Shading Language, GLSL)<29><>д<EFBFBD><D0B4>һ<EFBFBD><D2BB>С<EFBFBD><D0A1><EFBFBD><EFBFBD>,
// GLSL<53>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OpenGL<47><4C>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GLSL<53><4C><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFB7A8>Ҫ<EFBFBD><D2AA><EFBFBD>߲<EFBFBD><DFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB> <20><><EFBFBD><EFBFBD>
m_pVSHader = new QOpenGLShader(QOpenGLShader::Vertex, this);
//<2F><><EFBFBD><EFBFBD><EBB6A5><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool bCompile = m_pVSHader->compileSourceCode(vsrcyuv);
if(!bCompile)
{
// todo <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>״̬
}
//<2F><>ʼ<EFBFBD><CABC>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB> <20><><EFBFBD><EFBFBD>gpu<70><75>yuvת<76><D7AA><EFBFBD><EFBFBD>rgb
m_pFSHader = new QOpenGLShader(QOpenGLShader::Fragment, this);
if(mType == TYPE_RGB32){
bCompile = m_pFSHader->compileSourceCode(fsrcrgb);
}
if(mType == TYPE_YUV420P){
bCompile = m_pFSHader->compileSourceCode(fsrcyuv);
}
if(!bCompile)
{
// todo <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>״̬
}
#define PROGRAM_VERTEX_ATTRIBUTE 0
#define PROGRAM_TEXCOORD_ATTRIBUTE 1
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pShaderProgram = new QOpenGLShaderProgram;
//<2F><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pShaderProgram->addShader(m_pFSHader);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pShaderProgram->addShader(m_pVSHader);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>vertexIn<49><6E>ָ<EFBFBD><D6B8>λ<EFBFBD><CEBB>ATTRIB_VERTEX,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>ɫԴ<C9AB><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pShaderProgram->bindAttributeLocation("vertexIn", ATTRIB_VERTEX);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>textureIn<49><6E>ָ<EFBFBD><D6B8>λ<EFBFBD><CEBB>ATTRIB_TEXTURE,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>ɫԴ<C9AB><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pShaderProgram->bindAttributeLocation("textureIn", ATTRIB_TEXTURE);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB5BD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pShaderProgram->link();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pShaderProgram->bind();
if(this->mType == TYPE_YUV420P){
initShaderYuv();
}
if(this->mType == TYPE_RGB32){
initShaderRgb();
}
glClearColor(0.0,0.0,0.0,0.0);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
}
void CPlayWidget::resizeGL(int w, int h)
{
if(h == 0)// <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
h = 1;// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ1
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
glViewport(0,0, w,h);
}
void CPlayWidget::paintGL()
{
if(mType == TYPE_YUV420P)
loadYuvTexture();
if(mType == TYPE_RGB32){
loadRgbTexture();
}
//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<E9B7BD><CABD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
return;
}
void CPlayWidget::initShaderYuv()
{
//<2F><>ȡ<EFBFBD><C8A1>ɫ<EFBFBD><C9AB><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD>tex_y, tex_u, tex_v<5F><76>λ<EFBFBD><CEBB>,<2C><>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//Ƭ<><C6AC><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Դ<EFBFBD><D4B4><EFBFBD>п<EFBFBD><D0BF>Կ<EFBFBD><D4BF><EFBFBD>
textureUniformY = m_pShaderProgram->uniformLocation("tex_y");
textureUniformU = m_pShaderProgram->uniformLocation("tex_u");
textureUniformV = m_pShaderProgram->uniformLocation("tex_v");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static const GLfloat vertexVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static const GLfloat textureVertices[] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ATTRIB_VERTEX<45>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʽ
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ATTRIB_TEXTURE<52><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʽ
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices);
//<2F><><EFBFBD><EFBFBD>ATTRIB_VERTEX<45><58><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><><C4AC><EFBFBD>ǹرյ<D8B1>
glEnableVertexAttribArray(ATTRIB_VERTEX);
//<2F><><EFBFBD><EFBFBD>ATTRIB_TEXTURE<52><45><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><><C4AC><EFBFBD>ǹرյ<D8B1>
glEnableVertexAttribArray(ATTRIB_TEXTURE);
//<2F>ֱ𴴽<D6B1>y,u,v<><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pTextureY = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureU = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureV = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureY->create();
m_pTextureU->create();
m_pTextureV->create();
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
id_y = m_pTextureY->textureId();
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
id_u = m_pTextureU->textureId();
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>v<EFBFBD><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
id_v = m_pTextureV->textureId();
}
void CPlayWidget::initShaderRgb()
{
//<2F><>ȡ<EFBFBD><C8A1>ɫ<EFBFBD><C9AB><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD>tex_y, tex_u, tex_v<5F><76>λ<EFBFBD><CEBB>,<2C><>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//Ƭ<><C6AC><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Դ<EFBFBD><D4B4><EFBFBD>п<EFBFBD><D0BF>Կ<EFBFBD><D4BF><EFBFBD>
textureUniformRGB = m_pShaderProgram->uniformLocation("rgbdata");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static const GLfloat vertexVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static const GLfloat textureVertices[] = {
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ATTRIB_VERTEX<45>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʽ
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertexVertices);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ATTRIB_TEXTURE<52><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʽ
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, textureVertices);
//<2F><><EFBFBD><EFBFBD>ATTRIB_VERTEX<45><58><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><><C4AC><EFBFBD>ǹرյ<D8B1>
glEnableVertexAttribArray(ATTRIB_VERTEX);
//<2F><><EFBFBD><EFBFBD>ATTRIB_TEXTURE<52><45><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><><C4AC><EFBFBD>ǹرյ<D8B1>
glEnableVertexAttribArray(ATTRIB_TEXTURE);
//<2F>ֱ𴴽<D6B1>y,u,v<><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pTextureRGB = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_pTextureRGB->create();
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
id_rgb = m_pTextureRGB->textureId();
}
int CPlayWidget::loadYuvTexture()
{
//<2F><><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԪGL_TEXTURE0
glActiveTexture(GL_TEXTURE0);
//ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
glBindTexture(GL_TEXTURE_2D, id_y);
//ʹ<><CAB9><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>m_pBufYuv420p<30><70><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RED,
m_nVideoW,
m_nVideoH,
0,
GL_RED,
GL_UNSIGNED_BYTE,
m_pBufYuv420p);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//<2F><><EFBFBD><EFBFBD>u<EFBFBD><75><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
glActiveTexture(GL_TEXTURE1);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԪGL_TEXTURE1
glBindTexture(GL_TEXTURE_2D, id_u);
glTexImage2D(GL_TEXTURE_2D,
0, GL_RED,
m_nVideoW/2,
m_nVideoH/2,
0,
GL_RED,
GL_UNSIGNED_BYTE,
(char*)m_pBufYuv420p+m_nVideoW*m_nVideoH);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//<2F><><EFBFBD><EFBFBD>v<EFBFBD><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
glActiveTexture(GL_TEXTURE2);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԪGL_TEXTURE2
glBindTexture(GL_TEXTURE_2D, id_v);
glTexImage2D(GL_TEXTURE_2D,
0, GL_RED,
m_nVideoW/2,
m_nVideoH/2,
0, GL_RED,
GL_UNSIGNED_BYTE,
(char*)m_pBufYuv420p+m_nVideoW*m_nVideoH*5/4);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//ָ<><D6B8>y<EFBFBD><79><EFBFBD><EFBFBD>Ҫʹ<D2AA><CAB9><EFBFBD><EFBFBD>ֵ ֻ<><D6BB><EFBFBD><EFBFBD>0,1,2<>ȱ<EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>opengl<67><6C><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB>ĵط<C4B5>
//0<><30>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԪGL_TEXTURE0 1<><31>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԪGL_TEXTURE1 2<><32>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>Ԫ
glUniform1i(textureUniformY, 0);
//ָ<><D6B8>u<EFBFBD><75><EFBFBD><EFBFBD>Ҫʹ<D2AA><CAB9><EFBFBD><EFBFBD>ֵ
glUniform1i(textureUniformU, 1);
//ָ<><D6B8>v<EFBFBD><76><EFBFBD><EFBFBD>Ҫʹ<D2AA><CAB9><EFBFBD><EFBFBD>ֵ
glUniform1i(textureUniformV, 2);
return 0;
}
int CPlayWidget::loadRgbTexture()
{
//<2F><><EFBFBD><EFBFBD>rgb<67><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԪGL_TEXTURE0
glActiveTexture(GL_TEXTURE0);
//ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
glBindTexture(GL_TEXTURE_2D, id_rgb);
//ʹ<><CAB9><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>m_pBufYuv420p<30><70><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
m_nVideoW,
m_nVideoH,
0,
GL_BGRA,
GL_UNSIGNED_BYTE,
m_pBufRgb32);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glUniform1i(textureUniformRGB, 0);
return 0;
}