@@ -69,8 +69,7 @@ static const GLfloat s_colorConversion709[] = {
6969
7070namespace CGE
7171{
72- CGEVideoPlayerYUV420P::CGEVideoPlayerYUV420P () :
73- m_posAttribLocation (0 ), m_decodeHandler(nullptr ), m_vertexBuffer(0 )
72+ CGEVideoPlayerYUV420P::CGEVideoPlayerYUV420P ()
7473{
7574 m_program.bindAttribLocation (CGEImageFilterInterface::paramPositionIndexName, m_posAttribLocation);
7675
@@ -89,16 +88,16 @@ CGEVideoPlayerYUV420P::CGEVideoPlayerYUV420P() :
8988 m_texULoc = m_program.uniformLocation (" textureU" );
9089 m_texVLoc = m_program.uniformLocation (" textureV" );
9190
92- glUniform1i (m_texYLoc, 1 );
93- glUniform1i (m_texULoc, 2 );
94- glUniform1i (m_texVLoc, 3 );
95-
9691 if (m_texYLoc < 0 || m_texULoc < 0 || m_texVLoc < 0 )
9792 {
9893 CGE_LOG_ERROR (" Invalid YUV Texture Uniforms\n " );
9994 }
100-
101- memset (m_texYUV, 0 , sizeof (m_texYUV));
95+ else
96+ {
97+ glUniform1i (m_texYLoc, 1 );
98+ glUniform1i (m_texULoc, 2 );
99+ glUniform1i (m_texVLoc, 3 );
100+ }
102101
103102 m_rotLoc = m_program.uniformLocation (" rotation" );
104103 m_flipScaleLoc = m_program.uniformLocation (" flipScale" );
@@ -143,12 +142,6 @@ bool CGEVideoPlayerYUV420P::initWithDecodeHandler(CGEVideoDecodeHandler* handler
143142 m_linesize[2 ] = m_linesize[1 ] = m_linesize[0 ] / 2 ;
144143 m_videoHeight = m_decodeHandler->getHeight ();
145144
146- m_texYUV[0 ] = cgeGenTextureWithBuffer (nullptr , m_linesize[0 ], m_videoHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 , 1 );
147-
148- m_texYUV[1 ] = cgeGenTextureWithBuffer (nullptr , m_linesize[1 ], m_videoHeight / 2 , GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 , 2 );
149-
150- m_texYUV[2 ] = cgeGenTextureWithBuffer (nullptr , m_linesize[2 ], m_videoHeight / 2 , GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 , 3 );
151-
152145 if (m_vertexBuffer == 0 )
153146 m_vertexBuffer = cgeGenCommonQuadArrayBuffer ();
154147
@@ -245,23 +238,18 @@ bool CGEVideoPlayerYUV420P::updateVideoFrame(const CGEVideoFrameBufferData* data
245238
246239 m_program.bind ();
247240
248- if (m_linesize[0 ] != framebuffer.linesize [0 ])
241+ if (m_texYUV[ 0 ] == 0 || m_linesize[0 ] != framebuffer.linesize [0 ])
249242 {
250243 m_linesize[0 ] = framebuffer.linesize [0 ];
251244 m_linesize[1 ] = framebuffer.linesize [1 ];
252245 m_linesize[2 ] = framebuffer.linesize [2 ];
253246
254- glActiveTexture (GL_TEXTURE1);
255- glBindTexture (GL_TEXTURE_2D, m_texYUV[0 ]);
256- glTexImage2D (GL_TEXTURE_2D, 0 , GL_LUMINANCE, m_linesize[0 ], m_videoHeight, 0 , GL_LUMINANCE, GL_UNSIGNED_BYTE, framebuffer.data [0 ]);
257-
258- glActiveTexture (GL_TEXTURE2);
259- glBindTexture (GL_TEXTURE_2D, m_texYUV[1 ]);
260- glTexImage2D (GL_TEXTURE_2D, 0 , GL_LUMINANCE, m_linesize[1 ], m_videoHeight / 2 , 0 , GL_LUMINANCE, GL_UNSIGNED_BYTE, framebuffer.data [1 ]);
247+ if (m_texYUV[0 ] != 0 )
248+ glDeleteTextures (3 , m_texYUV);
261249
262- glActiveTexture (GL_TEXTURE3 );
263- glBindTexture (GL_TEXTURE_2D, m_texYUV[ 2 ] );
264- glTexImage2D (GL_TEXTURE_2D, 0 , GL_LUMINANCE , m_linesize[2 ], m_videoHeight / 2 , 0 , GL_LUMINANCE, GL_UNSIGNED_BYTE, framebuffer. data [ 2 ] );
250+ m_texYUV[ 0 ] = cgeGenTextureWithBuffer (framebuffer. data [ 0 ], m_linesize[ 0 ], m_videoHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 , 1 );
251+ m_texYUV[ 1 ] = cgeGenTextureWithBuffer (framebuffer. data [ 1 ], m_linesize[ 1 ], m_videoHeight / 2 , GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 , 2 );
252+ m_texYUV[ 2 ] = cgeGenTextureWithBuffer (framebuffer. data [ 2 ] , m_linesize[2 ], m_videoHeight / 2 , GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 , 3 );
265253 }
266254 else
267255 {
0 commit comments