Changeset 23d3f63ca53121de44137a0453f698f9d8d45bd9

Show
Ignore:
Timestamp:
22/07/04 18:37:43 (4 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1090514263 +0000
git-parent:

[031cb39a6f015aeaf347a6ec2e5394a258e9e415]

git-author:
Gildas Bazin <gbazin@videolan.org> 1090514263 +0000
Message:

* modules/video_output/x11/glx.c: improvements.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/video_output/x11/glx.c

    r4994baa r23d3f63  
    4040#include <GL/glx.h> 
    4141 
    42  
    4342/* Data common to vout and opengl provider structures */ 
    4443typedef struct glx_t 
     
    5352    GLXWindow   gwnd; 
    5453    Atom        wm_delete; 
     54 
    5555} glx_t; 
     56 
     57/* RV16 */ 
     58//#define VLCGL_RGB_FORMAT GL_RGB 
     59//#define VLCGL_RGB_TYPE GL_UNSIGNED_SHORT_5_6_5 
     60 
     61/* RV24 */ 
     62//#define VLCGL_RGB_FORMAT GL_RGB 
     63//#define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE 
     64 
     65/* RV32 */ 
     66#define VLCGL_RGB_FORMAT GL_RGBA 
     67#define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE 
    5668 
    5769 
     
    104116vlc_module_end(); 
    105117 
    106  
    107118/***************************************************************************** 
    108119 * vout_sys_t: GLX video output method descriptor 
     
    161172    p_vout->p_sys->i_effect = 1; 
    162173 
    163    /* p_vout->p_sys->glx.i_width = p_vout->i_window_width; 
    164     p_vout->p_sys->glx.i_height = p_vout->i_window_height; */ 
    165     p_vout->p_sys->glx.i_width = 700; 
    166     p_vout->p_sys->glx.i_height = 700; 
     174    p_vout->p_sys->glx.i_width = p_vout->i_window_width; 
     175    p_vout->p_sys->glx.i_height = p_vout->i_window_height; 
    167176    p_vout->p_sys->glx.b_fullscreen = 0; 
    168177 
     
    196205static int Init( vout_thread_t *p_vout ) 
    197206{ 
    198     int i_index; 
    199     picture_t *p_pic; 
     207    int i_pixel_pitch; 
    200208 
    201209    /* No YUV textures :( */ 
     210 
     211#if VLCGL_RGB_FORMAT == GL_RGB 
     212#   if VLCGL_RGB_TYPE == GL_UNSIGNED_BYTE 
     213    p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); 
     214    p_vout->output.i_rmask = 0x000000ff; 
     215    p_vout->output.i_gmask = 0x0000ff00; 
     216    p_vout->output.i_bmask = 0x00ff0000; 
     217    i_pixel_pitch = 3; 
     218#   else 
     219    p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); 
     220    p_vout->output.i_rmask = 0xf800; 
     221    p_vout->output.i_gmask = 0x07e0; 
     222    p_vout->output.i_bmask = 0x001f; 
     223    i_pixel_pitch = 2; 
     224#   endif 
     225#else 
    202226    p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); 
    203227    p_vout->output.i_rmask = 0x000000ff; 
    204228    p_vout->output.i_gmask = 0x0000ff00; 
    205229    p_vout->output.i_bmask = 0x00ff0000; 
    206  
     230    i_pixel_pitch = 4; 
     231#endif 
     232 
     233    /* Since OpenGL can do rescaling for us, stick to the default 
     234     * coordinates and aspect. */ 
    207235    p_vout->output.i_width  = p_vout->render.i_width; 
    208236    p_vout->output.i_height = p_vout->render.i_height; 
    209237    p_vout->output.i_aspect = p_vout->render.i_aspect; 
    210238 
    211     I_OUTPUTPICTURES = 0; 
    212  
    213     p_pic = NULL; 
    214  
    215     /* Find an empty picture slot */ 
    216     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) 
    217     { 
    218         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) 
    219         { 
    220             p_pic = p_vout->p_picture + i_index; 
    221             break; 
    222         } 
    223     } 
    224  
    225     if( p_pic == NULL ) 
    226     { 
    227         return -1; 
    228     } 
    229  
    230    /* We know the chroma, allocate a buffer which will be used 
     239    /* We know the chroma, allocate a buffer which will be used 
    231240     * directly by the decoder */ 
    232     p_pic->i_planes = 1; 
    233  
     241    p_vout->p_picture[0].i_planes = 1; 
    234242    p_vout->p_sys->p_buffer = 
    235         malloc( p_vout->p_sys->i_tex_width * p_vout->p_sys->i_tex_height * 4 ); 
     243        malloc( p_vout->p_sys->i_tex_width * p_vout->p_sys->i_tex_height * 
     244                i_pixel_pitch ); 
    236245    if( !p_vout->p_sys->p_buffer ) 
    237246    { 
     
    240249    } 
    241250 
    242     p_pic->p->p_pixels = p_vout->p_sys->p_buffer 
    243         + 2 * p_vout->p_sys->i_tex_width * 
    244           (p_vout->p_sys->i_tex_height - p_vout->output.i_height) 
    245         + 2 * (p_vout->p_sys->i_tex_width - p_vout->output.i_width); 
    246     p_pic->p->i_lines = p_vout->output.i_height; 
    247     p_pic->p->i_pitch = p_vout->p_sys->i_tex_width * 4; 
    248     p_pic->p->i_pixel_pitch = 4; 
    249     p_pic->p->i_visible_pitch = p_vout->output.i_width * 4; 
    250  
    251     p_pic->i_status = DESTROYED_PICTURE; 
    252     p_pic->i_type   = DIRECT_PICTURE; 
    253  
    254     PP_OUTPUTPICTURE[ 0 ] = p_pic; 
    255  
     251    p_vout->p_picture[0].p->p_pixels = p_vout->p_sys->p_buffer; 
     252    p_vout->p_picture[0].p->i_lines = p_vout->output.i_height; 
     253    p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch; 
     254    p_vout->p_picture[0].p->i_pitch = p_vout->p_sys->i_tex_width * 
     255        p_vout->p_picture[0].p->i_pixel_pitch; 
     256    p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width * 
     257        p_vout->p_picture[0].p->i_pixel_pitch; 
     258 
     259    p_vout->p_picture[0].i_status = DESTROYED_PICTURE; 
     260    p_vout->p_picture[0].i_type   = DIRECT_PICTURE; 
     261 
     262    PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0]; 
    256263    I_OUTPUTPICTURES = 1; 
    257264 
     
    260267    /* Set the texture parameters */ 
    261268    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 
    262     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 
     269    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 
    263270 
    264271    if( p_vout->p_sys->i_effect ) 
    265272    { 
    266273        glEnable( GL_CULL_FACE); 
    267 /*        glDisable( GL_DEPTH_TEST ); 
     274        /* glDisable( GL_DEPTH_TEST ); 
    268275        glEnable( GL_BLEND ); 
    269276        glBlendFunc( GL_SRC_ALPHA, GL_ONE );*/ 
     
    309316} 
    310317 
    311  
    312318/***************************************************************************** 
    313319 * CreateOpenGL: initialize an OpenGL provider 
     
    330336} 
    331337 
    332  
    333338/***************************************************************************** 
    334339 * DestroyOpenGL: destroys an OpenGL provider 
     
    363368} 
    364369 
    365  
    366370/***************************************************************************** 
    367371 * SwapBuffers: swap front/back buffers 
     
    380384    } 
    381385} 
    382  
    383386 
    384387/***************************************************************************** 
     
    396399    return i_ret; 
    397400} 
    398  
    399401 
    400402/***************************************************************************** 
     
    420422    return 0; 
    421423} 
    422  
    423424 
    424425static int HandleX11Events( vlc_object_t *p_thread, glx_t *p_glx ) 
     
    451452} 
    452453 
    453  
    454454/***************************************************************************** 
    455455 * Render: render previously calculated output 
     
    457457static void Render( vout_thread_t *p_vout, picture_t *p_pic ) 
    458458{ 
     459    vout_sys_t *p_sys = p_vout->p_sys; 
     460    float f_width = (float)p_vout->output.i_width / p_sys->i_tex_width; 
     461    float f_height = (float)p_vout->output.i_height / p_sys->i_tex_height; 
     462 
    459463    glClear(GL_COLOR_BUFFER_BIT); 
    460     /*glTexImage2D (GL_TEXTURE_2D, 0, 3, p_vout->output.i_width, 
    461                   p_vout->output.i_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
    462                   p_vout->p_sys->p_buffer);*/ 
     464 
    463465    glTexImage2D (GL_TEXTURE_2D, 0, 3, p_vout->p_sys->i_tex_width, 
    464                   p_vout->p_sys->i_tex_height , 0, GL_RGBA, GL_UNSIGNED_BYTE, 
     466                  p_vout->p_sys->i_tex_height , 0, 
     467                  VLCGL_RGB_FORMAT, VLCGL_RGB_TYPE, 
    465468                  p_vout->p_sys->p_buffer); 
    466469 
    467470    if( !p_vout->p_sys->i_effect ) 
    468471    { 
    469         glEnable( GL_TEXTURE_2D); 
    470         glBegin( GL_POLYGON); 
    471         glTexCoord2f(0.0,0.0); glVertex2f(-1.0,1.0); 
    472         glTexCoord2f(1.0,0.0); glVertex2f(1.0,1.0); 
    473         glTexCoord2f(1.0,1.0); glVertex2f(1.0,-1.0); 
    474         glTexCoord2f(0.0,1.0); glVertex2f(-1.0,-1.0); 
     472        glEnable( GL_TEXTURE_2D ); 
     473        glBegin( GL_POLYGON ); 
     474        glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, 1.0 ); 
     475        glTexCoord2f( f_width, 0.0 ); glVertex2f( 1.0, 1.0 ); 
     476        glTexCoord2f( f_width, f_height ); glVertex2f( 1.0, -1.0 ); 
     477        glTexCoord2f( 0.0, f_height ); glVertex2f( -1.0, -1.0 ); 
    475478        glEnd(); 
    476479    } 
     
    479482        glRotatef( 1.0, 0.3, 0.5, 0.7 ); 
    480483 
    481         glEnable( GL_TEXTURE_2D); 
     484        glEnable( GL_TEXTURE_2D ); 
    482485        glBegin( GL_QUADS ); 
    483486 
    484         float f_width = p_vout->output.i_width; 
    485         float f_height = p_vout->output.i_height; 
    486  
    487         /* Correct the aspect ratio */ 
    488  /*       float f_aspect = (float)p_vout->output.i_aspect / VOUT_ASPECT_FACTOR; 
    489         if( f_aspect > 1.0 ) 
    490         { 
    491             f_height *= f_aspect; 
    492         } 
    493         else 
    494         { 
    495             f_width *= f_aspect; 
    496         }*/ 
    497  
    498         float f_offset_x = (1.0 - f_width / p_vout->p_sys->i_tex_width) / 2.0; 
    499         float f_offset_y = (1.0 - f_height / p_vout->p_sys->i_tex_height) / 2.0; 
    500  
    501487        /* Front */ 
    502         glTexCoord2f( f_offset_x, f_offset_y ); 
    503         glVertex3f( - 1.0, 1.0, 1.0 ); 
    504         glTexCoord2f( f_offset_x, 1.0 - f_offset_y ); 
    505         glVertex3f( - 1.0, - 1.0, 1.0 ); 
    506         glTexCoord2f( 1.0 - f_offset_x, 1.0 - f_offset_y ); 
    507         glVertex3f( 1.0, - 1.0, 1.0 ); 
    508         glTexCoord2f( 1.0 - f_offset_x, f_offset_y ); 
    509         glVertex3f( 1.0, 1.0, 1.0 ); 
     488        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, 1.0 ); 
     489        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 ); 
     490        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, 1.0 ); 
     491        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, 1.0 ); 
    510492 
    511493        /* Left */ 
    512         glTexCoord2f( f_offset_x, f_offset_y ); 
    513         glVertex3f( - 1.0, 1.0, - 1.0 ); 
    514         glTexCoord2f( f_offset_x, 1.0 - f_offset_y ); 
    515         glVertex3f( - 1.0, - 1.0, - 1.0 ); 
    516         glTexCoord2f( 1.0 - f_offset_x, 1.0 - f_offset_y ); 
    517         glVertex3f( - 1.0, - 1.0, 1.0 ); 
    518         glTexCoord2f( 1.0 - f_offset_x, f_offset_y ); 
    519         glVertex3f( - 1.0, 1.0, 1.0 ); 
     494        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 ); 
     495        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 ); 
     496        glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 ); 
     497        glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, 1.0 ); 
    520498 
    521499        /* Back */ 
    522         glTexCoord2f( f_offset_x, f_offset_y ); 
    523         glVertex3f( 1.0, 1.0, - 1.0 ); 
    524         glTexCoord2f( f_offset_x, 1.0 - f_offset_y ); 
    525         glVertex3f( 1.0, - 1.0, - 1.0 ); 
    526         glTexCoord2f( 1.0 - f_offset_x, 1.0 - f_offset_y ); 
    527         glVertex3f( - 1.0, - 1.0, - 1.0 ); 
    528         glTexCoord2f( 1.0 - f_offset_x, f_offset_y ); 
    529         glVertex3f( - 1.0, 1.0, - 1.0 ); 
     500        glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, - 1.0 ); 
     501        glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 ); 
     502        glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 ); 
     503        glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 ); 
    530504 
    531505        /* Right */ 
    532         glTexCoord2f( f_offset_x, f_offset_y ); 
    533         glVertex3f( 1.0, 1.0, 1.0 ); 
    534         glTexCoord2f( f_offset_x, 1.0 - f_offset_y ); 
    535         glVertex3f( 1.0, - 1.0, 1.0 ); 
    536         glTexCoord2f( 1.0 - f_offset_x, 1.0 - f_offset_y ); 
    537         glVertex3f( 1.0, - 1.0, - 1.0 ); 
    538         glTexCoord2f( 1.0 - f_offset_x, f_offset_y ); 
    539         glVertex3f( 1.0, 1.0, - 1.0 ); 
     506        glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, 1.0 ); 
     507        glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, 1.0 ); 
     508        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 ); 
     509        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 ); 
    540510 
    541511        /* Top */ 
    542         glTexCoord2f( f_offset_x, f_offset_y ); 
    543         glVertex3f( - 1.0, 1.0, - 1.0 ); 
    544         glTexCoord2f( f_offset_x, 1.0 - f_offset_y ); 
    545         glVertex3f( - 1.0, 1.0, 1.0 ); 
    546         glTexCoord2f( 1.0 - f_offset_x, 1.0 - f_offset_y ); 
    547         glVertex3f( 1.0, 1.0, 1.0 ); 
    548         glTexCoord2f( 1.0 - f_offset_x, f_offset_y ); 
    549         glVertex3f( 1.0, 1.0, - 1.0 ); 
     512        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 ); 
     513        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, 1.0, 1.0 ); 
     514        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, 1.0, 1.0 ); 
     515        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 ); 
    550516 
    551517        /* Bottom */ 
    552         glTexCoord2f( f_offset_x, f_offset_y ); 
    553         glVertex3f( - 1.0, - 1.0, 1.0 ); 
    554         glTexCoord2f( f_offset_x, 1.0 - f_offset_y ); 
    555         glVertex3f( - 1.0, - 1.0, - 1.0 ); 
    556         glTexCoord2f( 1.0 - f_offset_x, 1.0 - f_offset_y ); 
    557         glVertex3f( 1.0, - 1.0, - 1.0 ); 
    558         glTexCoord2f( 1.0 - f_offset_x, f_offset_y ); 
    559         glVertex3f( 1.0, - 1.0, 1.0 ); 
     518        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, - 1.0, 1.0 ); 
     519        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 ); 
     520        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 ); 
     521        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, - 1.0, 1.0 ); 
    560522        glEnd(); 
    561523    } 
     524 
    562525    glDisable( GL_TEXTURE_2D); 
    563526} 
    564  
    565527 
    566528/***************************************************************************** 
     
    580542    } 
    581543} 
    582  
    583544 
    584545/***************************************************************************** 
     
    673634} 
    674635 
    675  
    676636int InitGLX12( vlc_object_t *p_thread, glx_t *p_glx ) 
    677637{ 
     
    707667    return 0; 
    708668} 
    709  
    710669 
    711670int InitGLX13( vlc_object_t *p_thread, glx_t *p_glx ) 
     
    770729    return 0; 
    771730} 
    772  
    773731 
    774732void CreateWindow( vlc_object_t *p_thread, glx_t *p_glx, XVisualInfo *p_vi ) 
     
    825783} 
    826784 
    827  
    828785void SwitchContext( glx_t *p_glx ) 
    829786{ 
     
    840797    } 
    841798} 
    842  
    843799 
    844800int GetAlignedSize( int i_size )