⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opengl.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
#       endif    i_pixel_pitch = 2;#   endif#else    p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');#       if defined( WORDS_BIGENDIAN )    p_vout->output.i_rmask = 0xff000000;    p_vout->output.i_gmask = 0x00ff0000;    p_vout->output.i_bmask = 0x0000ff00;#       else    p_vout->output.i_rmask = 0x000000ff;    p_vout->output.i_gmask = 0x0000ff00;    p_vout->output.i_bmask = 0x00ff0000;#       endif    i_pixel_pitch = 4;#endif    /* Since OpenGL can do rescaling for us, stick to the default     * coordinates and aspect. */    p_vout->output.i_width  = p_vout->render.i_width;    p_vout->output.i_height = p_vout->render.i_height;    p_vout->output.i_aspect = p_vout->render.i_aspect;    p_vout->fmt_out = p_vout->fmt_in;    p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;    /* We know the chroma, allocate one buffer which will be used     * directly by the decoder */    p_sys->pp_buffer[0] =        malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );    if( !p_sys->pp_buffer[0] )    {        msg_Err( p_vout, "out of memory" );        return -1;    }    p_sys->pp_buffer[1] =        malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );    if( !p_sys->pp_buffer[1] )    {        msg_Err( p_vout, "out of memory" );        return -1;    }    p_vout->p_picture[0].i_planes = 1;    p_vout->p_picture[0].p->p_pixels = p_sys->pp_buffer[0];    p_vout->p_picture[0].p->i_lines = p_vout->output.i_height;    p_vout->p_picture[0].p->i_visible_lines = p_vout->output.i_height;    p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch;    p_vout->p_picture[0].p->i_pitch = p_vout->output.i_width *        p_vout->p_picture[0].p->i_pixel_pitch;    p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width *        p_vout->p_picture[0].p->i_pixel_pitch;    p_vout->p_picture[0].i_status = DESTROYED_PICTURE;    p_vout->p_picture[0].i_type   = DIRECT_PICTURE;    PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0];    I_OUTPUTPICTURES = 1;    if( p_sys->p_vout->pf_lock &&        p_sys->p_vout->pf_lock( p_sys->p_vout ) )    {        msg_Warn( p_vout, "could not lock OpenGL provider" );        return 0;    }    InitTextures( p_vout );    glDisable(GL_BLEND);    glDisable(GL_DEPTH_TEST);    glDepthMask(GL_FALSE);    glDisable(GL_CULL_FACE);    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );    glClear( GL_COLOR_BUFFER_BIT );    /* Check if the user asked for useless visual effects */    var_Get( p_vout, "opengl-effect", &val );    if( !val.psz_string || !strcmp( val.psz_string, "none" ))    {        p_sys->i_effect = OPENGL_EFFECT_NONE;    }    else if( !strcmp( val.psz_string, "cube" ) )    {        p_sys->i_effect = OPENGL_EFFECT_CUBE;        glEnable( GL_CULL_FACE);    }    else if( !strcmp( val.psz_string, "transparent-cube" ) )    {        p_sys->i_effect = OPENGL_EFFECT_TRANSPARENT_CUBE;        glDisable( GL_DEPTH_TEST );        glEnable( GL_BLEND );        glBlendFunc( GL_SRC_ALPHA, GL_ONE );    }    else    {#ifdef OPENGL_MORE_EFFECT		p_sys->i_effect = 3;        while (( strcmp( val.psz_string, ppsz_effects[p_sys->i_effect]) ) && (pow(2,p_sys->i_effect) < INIFILE))        {            p_sys->i_effect ++;        }		if (pow(2,p_sys->i_effect) < INIFILE) 			p_sys->i_effect = pow(2,p_sys->i_effect);		else if ( strcmp( val.psz_string, ppsz_effects[p_sys->i_effect]))		{			msg_Warn( p_vout, "no valid opengl effect provided, using "					  "\"none\"" );			p_sys->i_effect = OPENGL_EFFECT_NONE;		}#else        msg_Warn( p_vout, "no valid opengl effect provided, using "                  "\"none\"" );        p_sys->i_effect = OPENGL_EFFECT_NONE;#endif    }    if( val.psz_string ) free( val.psz_string );    if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |                OPENGL_EFFECT_TRANSPARENT_CUBE ) )    {        /* Set the perpective */        glMatrixMode( GL_PROJECTION );        glLoadIdentity();        glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );        glMatrixMode( GL_MODELVIEW );        glLoadIdentity();        glTranslatef( 0.0, 0.0, - 5.0 );    }#ifdef OPENGL_MORE_EFFECT	else     {        /* Set the perpective */        glMatrixMode( GL_PROJECTION );        glLoadIdentity();        glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );        glMatrixMode( GL_MODELVIEW );        glLoadIdentity();        glTranslatef( 0.0, 0.0, -3.0 );		float f_pov_x, f_pov_y, f_pov_z;		f_pov_x = var_CreateGetFloat( p_vout, "opengl-pov-x");		f_pov_y = var_CreateGetFloat( p_vout, "opengl-pov-y");		f_pov_z = var_CreateGetFloat( p_vout, "opengl-pov-z");		gluLookAt(0, 0, 0, f_pov_x, f_pov_y, f_pov_z, 0, 1, 0);    }#endif    if( p_sys->p_vout->pf_unlock )    {        p_sys->p_vout->pf_unlock( p_sys->p_vout );    }    return 0;}/***************************************************************************** * End: terminate GLX video thread output method *****************************************************************************/static void End( vout_thread_t *p_vout ){    vout_sys_t *p_sys = p_vout->p_sys;    if( p_sys->p_vout->pf_lock &&        p_sys->p_vout->pf_lock( p_sys->p_vout ) )    {        msg_Warn( p_vout, "could not lock OpenGL provider" );        return;    }    glFinish();    glFlush();    /* Free the texture buffer*/    glDeleteTextures( 2, p_sys->p_textures );    if( p_sys->pp_buffer[0] ) free( p_sys->pp_buffer[0] );    if( p_sys->pp_buffer[1] ) free( p_sys->pp_buffer[1] );    if( p_sys->p_vout->pf_unlock )    {        p_sys->p_vout->pf_unlock( p_sys->p_vout );    }}/***************************************************************************** * Destroy: destroy GLX video thread output method ***************************************************************************** * Terminate an output method created by CreateVout *****************************************************************************/static void DestroyVout( vlc_object_t *p_this ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;    vout_sys_t *p_sys = p_vout->p_sys;    module_Unneed( p_sys->p_vout, p_sys->p_vout->p_module );    vlc_object_detach( p_sys->p_vout );    vlc_object_destroy( p_sys->p_vout );    free( p_sys );}/***************************************************************************** * Manage: handle Sys events ***************************************************************************** * This function should be called regularly by video output thread. It returns * a non null value if an error occurred. *****************************************************************************/static int Manage( vout_thread_t *p_vout ){    vout_sys_t *p_sys = p_vout->p_sys;    int i_ret, i_fullscreen_change;    i_fullscreen_change = ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE );    p_vout->fmt_out.i_x_offset = p_sys->p_vout->fmt_in.i_x_offset =        p_vout->fmt_in.i_x_offset;    p_vout->fmt_out.i_y_offset = p_sys->p_vout->fmt_in.i_y_offset =        p_vout->fmt_in.i_y_offset;    p_vout->fmt_out.i_visible_width = p_sys->p_vout->fmt_in.i_visible_width =        p_vout->fmt_in.i_visible_width;    p_vout->fmt_out.i_visible_height = p_sys->p_vout->fmt_in.i_visible_height =        p_vout->fmt_in.i_visible_height;    p_vout->fmt_out.i_aspect = p_sys->p_vout->fmt_in.i_aspect =        p_vout->fmt_in.i_aspect;    p_vout->fmt_out.i_sar_num = p_sys->p_vout->fmt_in.i_sar_num =        p_vout->fmt_in.i_sar_num;    p_vout->fmt_out.i_sar_den = p_sys->p_vout->fmt_in.i_sar_den =        p_vout->fmt_in.i_sar_den;    p_vout->output.i_aspect = p_vout->fmt_in.i_aspect;    p_sys->p_vout->i_changes = p_vout->i_changes;    i_ret = p_sys->p_vout->pf_manage( p_sys->p_vout );    p_vout->i_changes = p_sys->p_vout->i_changes;#ifdef __APPLE__    if( p_sys->p_vout->pf_lock &&        p_sys->p_vout->pf_lock( p_sys->p_vout ) )    {        msg_Warn( p_vout, "could not lock OpenGL provider" );        return i_ret;    }    /* On OS X, we create the window and the GL view when entering       fullscreen - the textures have to be inited again */    if( i_fullscreen_change )    {        InitTextures( p_vout );        switch( p_sys->i_effect )        {            case OPENGL_EFFECT_CUBE:#ifdef OPENGL_MORE_EFFECT			case CYLINDER:			case TORUS:			case SPHERE:			case SQUAREXY:			case SQUARER:			case ASINXY:			case ASINR:			case SINEXY:			case SINER:#endif                            glEnable( GL_CULL_FACE );                break;            case OPENGL_EFFECT_TRANSPARENT_CUBE:                glDisable( GL_DEPTH_TEST );                glEnable( GL_BLEND );                glBlendFunc( GL_SRC_ALPHA, GL_ONE );                break;        }        if( p_sys->i_effect & ( OPENGL_EFFECT_CUBE |                    OPENGL_EFFECT_TRANSPARENT_CUBE ) )        {            /* Set the perpective */            glMatrixMode( GL_PROJECTION );            glLoadIdentity();            glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );            glMatrixMode( GL_MODELVIEW );            glLoadIdentity();            glTranslatef( 0.0, 0.0, - 5.0 );        }#ifdef OPENGL_MORE_EFFECT		else 	    {	        glMatrixMode( GL_PROJECTION );	        glLoadIdentity();	        glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );	        glMatrixMode( GL_MODELVIEW );	        glLoadIdentity();	        glTranslatef( 0.0, 0.0, -3.0 );				float f_pov_x, f_pov_y, f_pov_z;			f_pov_x = var_CreateGetFloat( p_vout, "opengl-pov-x");			f_pov_y = var_CreateGetFloat( p_vout, "opengl-pov-y");			f_pov_z = var_CreateGetFloat( p_vout, "opengl-pov-z");			gluLookAt(0, 0, 0, f_pov_x, f_pov_y, f_pov_z, 0, 1, 0);	    }#endif            }    if( p_sys->p_vout->pf_unlock )    {        p_sys->p_vout->pf_unlock( p_sys->p_vout );    }#endif// to align in real time in OPENGL	if (p_sys->p_vout->i_alignment != p_vout->i_alignment)	{		p_vout->i_changes = VOUT_CROP_CHANGE;		//to force change    	p_sys->p_vout->i_alignment = p_vout->i_alignment;		}	    return i_ret;}/***************************************************************************** * Render: render previously calculated output *****************************************************************************/static void Render( vout_thread_t *p_vout, picture_t *p_pic ){    vout_sys_t *p_sys = p_vout->p_sys;    /* On Win32/GLX, we do this the usual way:       + Fill the buffer with new content,       + Reload the texture,       + Use the texture.       On OS X with VRAM or AGP texturing, the order has to be:       + Reload the texture,       + Fill the buffer with new content,       + Use the texture.       (Thanks to gcc from the Arstechnica forums for the tip)       Therefore, we have to use two buffers and textures. On Win32/GLX,       we reload the texture to be displayed and use it right away. On       OS X, we first render, then reload the texture to be used next       time. */    if( p_sys->p_vout->pf_lock &&        p_sys->p_vout->pf_lock( p_sys->p_vout ) )    {        msg_Warn( p_vout, "could not lock OpenGL provider" );        return;    }#ifdef __APPLE__    int i_new_index;    i_new_index = ( p_sys->i_index + 1 ) & 1;    /* Update the texture */    glBindTexture( VLCGL_TARGET, p_sys->p_textures[i_new_index] );    glTexSubImage2D( VLCGL_TARGET, 0, 0, 0,                     p_vout->fmt_out.i_width,                     p_vout->fmt_out.i_height,                     VLCGL_FORMAT, VLCGL_TYPE, p_sys->pp_buffer[i_new_index] );    /* Bind to the previous texture for drawing */    glBindTexture( VLCGL_TARGET, p_sys->p_textures[p_sys->i_index] );    /* Switch buffers */    p_sys->i_index = i_new_index;    p_pic->p->p_pixels = p_sys->pp_buffer[p_sys->i_index];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -