Ticket #2383: vsync.patch
File vsync.patch, 4.5 KB (added by , 18 years ago) |
---|
-
vsync.cpp
35 35 #include "util-x11.h" // for OpenGL VSync 36 36 37 37 #ifdef USING_OPENGL_VSYNC 38 #define GLX_GLXEXT_PROTOTYPES39 38 #define XMD_H 1 40 39 #include <GL/glx.h> 41 40 #include <GL/gl.h> … … 437 436 UpdateNexttrigger(); 438 437 } 439 438 439 #ifdef USING_OPENGL_VSYNC 440 class OpenGLVideoSyncPrivate 441 { 442 public: 443 OpenGLVideoSyncPrivate() 444 { 445 glXGetProcAddress("glXGetVideoSyncSGI", m_glXGetVideoSyncSGI); 446 glXGetProcAddress("glXWaitVideoSyncSGI", m_glXWaitVideoSyncSGI); 447 } 448 449 bool funcsLoaded() 450 { 451 return m_glXGetVideoSyncSGI && m_glXWaitVideoSyncSGI; 452 } 453 454 public: 455 int glXGetVideoSyncSGI(unsigned int *count) 456 { 457 return m_glXGetVideoSyncSGI(count); 458 } 459 460 int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) 461 { 462 return m_glXWaitVideoSyncSGI(divisor, remainder, count); 463 } 464 465 private: 466 template <typename T> 467 void glXGetProcAddress(const char * const procName, T &ret) 468 { 469 ret = reinterpret_cast<T>(glXGetProcAddressARB((const GLubyte *) 470 procName)); 471 if (!ret) 472 { 473 VERBOSE(VB_PLAYBACK, 474 QString("Error: glXGetProcAddressARB unable to find %1") 475 .arg(procName)); 476 } 477 } 478 479 private: 480 PFNGLXGETVIDEOSYNCSGIPROC m_glXGetVideoSyncSGI; 481 PFNGLXWAITVIDEOSYNCSGIPROC m_glXWaitVideoSyncSGI; 482 }; 483 #endif // USING_OPENGL_VSYNC 484 440 485 OpenGLVideoSync::OpenGLVideoSync(VideoOutput *video_output, 441 486 int frame_interval, int refresh_interval, 442 487 bool interlaced) 443 488 : VideoSync(video_output, frame_interval, refresh_interval, interlaced), 444 m_drawable(0), m_context(0) 489 m_drawable(0), m_context(0), m_imp(0) 445 490 { 491 #ifdef USING_OPENGL_VSYNC 492 m_imp = new OpenGLVideoSyncPrivate; 493 #endif // USING_OPENGL_VSYNC 446 494 } 447 495 448 496 OpenGLVideoSync::~OpenGLVideoSync() … … 457 505 if (m_drawable) 458 506 X11S(XDestroyWindow(vo->XJ_disp, m_drawable)); 459 507 } 508 delete m_imp; 460 509 #endif /* USING_OPENGL_VSYNC */ 461 510 } 462 511 … … 503 552 return false; 504 553 } 505 554 555 if (!m_imp->funcsLoaded()) 556 { 557 VERBOSE(VB_PLAYBACK, QString("GL sync functions not found")); 558 return false; 559 } 560 506 561 int attribList[] = {GLX_RGBA, 507 562 GLX_RED_SIZE, 1, 508 563 GLX_GREEN_SIZE, 1, … … 552 607 if (ret != False) 553 608 { 554 609 unsigned int count; 555 X11S(ret = glXGetVideoSyncSGI(&count));610 X11S(ret = m_imp->glXGetVideoSyncSGI(&count)); 556 611 if (ret == 0) 557 612 { 558 613 VERBOSE(VB_PLAYBACK, "Using OpenGLVideoSync"); … … 631 686 632 687 // Wait for a refresh so we start out synched 633 688 unsigned int count; 634 err = glXGetVideoSyncSGI(&count);689 err = m_imp->glXGetVideoSyncSGI(&count); 635 690 checkGLSyncError("OpenGLVideoSync::Start(): Frame Number Query", err); 636 err = glXWaitVideoSyncSGI(2, (count+1)%2 ,&count);691 err = m_imp->glXWaitVideoSyncSGI(2, (count+1)%2 ,&count); 637 692 checkGLSyncError("OpenGLVideoSync::Start(): A/V Sync", err); 638 693 639 694 // Initialize next trigger … … 649 704 OffsetTimeval(m_nexttrigger, sync_delay); 650 705 651 706 unsigned int frameNum = 0; 652 int err = glXGetVideoSyncSGI(&frameNum);707 int err = m_imp->glXGetVideoSyncSGI(&frameNum); 653 708 checkGLSyncError("Frame Number Query", err); 654 709 655 710 // Always sync to the next retrace execpt when we are very late. 656 711 if ((m_delay = CalcDelay()) > -(m_refresh_interval/2)) 657 712 { 658 err = glXWaitVideoSyncSGI(2, (frameNum+1)%2 ,&frameNum);713 err = m_imp->glXWaitVideoSyncSGI(2, (frameNum+1)%2 ,&frameNum); 659 714 checkGLSyncError(msg1, err); 660 715 m_delay = CalcDelay(); 661 716 } … … 664 719 if (m_delay > 0) 665 720 { 666 721 uint n = m_delay / m_refresh_interval + 1; 667 err = glXWaitVideoSyncSGI((n+1), (frameNum+n)%(n+1), &frameNum);722 err = m_imp->glXWaitVideoSyncSGI((n+1), (frameNum+n)%(n+1), &frameNum); 668 723 checkGLSyncError(msg2, err); 669 724 m_delay = CalcDelay(); 670 725 } -
vsync.h
214 214 private: 215 215 GLXDrawable m_drawable; 216 216 GLXContext m_context; 217 private: 218 class OpenGLVideoSyncPrivate *m_imp; 217 219 }; 218 220 219 221 #ifdef __linux__