• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[Long] flicker issue using an NSOpenGLView / resent
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Long] flicker issue using an NSOpenGLView / resent


  • Subject: [Long] flicker issue using an NSOpenGLView / resent
  • From: "eric.bachard" <email@hidden>
  • Date: Tue, 02 Sep 2008 08:55:07 +0200

[my apologies if ever you receive the mail twice]

Hi,

I'm writing to the list, because I got a problem I can't solve, even after reading a lot of archives about possible wrong thing we do, and searching a lot on the web.

First, the code was initialy written in C++, and adding the NSOpenGLView it is now ObjC++ :) What we do, is simply create an NSOpenGLView, and we add it in an NSView, using addSubview. Then we draw the OpenGL scene, and when we removeFromSubview, we got a white screen.

What could cause that, and what do you suggest ? Shall I create a customized NSView instead of use the NSOpenGLView?

Below, I put what I thought important. I tried to make it as short as possible, but if you need more information, just tell me.


Thanks in advance for any help :)


The code now. ...

... first, we create a structure containing some information ( in the class ):

    /// Holds the information of our new child window
    struct GLWindow
    {
NSOpenGLView* pOpenGLView; // Custom Cocoa NSOpenGLView
        NSOpenGLContext*        pOpenGLContext; // our OpenGLContext
        NSRect                  aInitFrame;
    unsigned int bpp;
    unsigned int            Width;
    unsigned int            Height;
    } GLWin;

Second, we define the PixelFormat :

GLuint attribs[] =
{
// Specifying "NoRecovery" gives us a context that cannot fall back to the software renderer.
// This makes the View-based context a compatible with the fullscreen context,
// enabling us to use the "shareContext" feature to share textures, display lists,
// and other OpenGL objects between the two.
NSOpenGLPFANoRecovery,


// Specify that we want a Window OpenGL context.
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
// needed
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 16, // In some code sample, attributes Common to FullScreen and non-FullScreen recommand 16
0
};


And we initialize it in void OGLTransitionerImpl::initWindowFromSlideShowView() :


... ( some code )

NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*) attribs];
Window *pFrameWindow = pPWindow->GetWindow(WINDOW_FRAME);
Size aFrameSize( pFrameWindow->GetSizePixel() );
Point aScreen( pPWindow->OutputToScreenPixel( Point() ) );
GLWin.aInitFrame = (NSRect){ { aScreen.X(), aFrameSize.Height() - GLWin.Height - aScreen.Y() }, { GLWin.Width, GLWin.Height } };


GLWin.pOpenGLView = [[NSOpenGLView alloc] initWithFrame: GLWin.aInitFrame pixelFormat: [fmt autorelease]];


... then we add the NSOpenGLView to the NSView (a customized NSView)

OSL_ENSURE(GLWin.pOpenGLView, "Could not create NSOPenGLView");
    if( !GLWin.pOpenGLView )
return;

    [sysData->pView addSubview:GLWin.pOpenGLView];
    [[GLWin.pOpenGLView openGLContext] makeCurrentContext];


... we do some mandatory operations

    if( pWindow )
    {
        pWindow->SetMouseTransparent( TRUE );
        pWindow->SetParentClipMode( PARENTCLIPMODE_NOCLIP );
        pWindow->EnableEraseBackground( FALSE );
        pWindow->SetControlForeground();
        pWindow->SetControlBackground();
        pWindow->EnablePaint(FALSE);

pWindow->SetPosSizePixel(pPWindow->GetPosPixel(),pPWindow->GetSizePixel());

    }

... and finally, we prepare the OpenGL engine :

    glShadeModel( GL_SMOOTH );
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);  // R G B A
    glClear(GL_COLOR_BUFFER_BIT);
    glClearDepth( 1.0f );
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LEQUAL );
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
    glEnable(GL_TEXTURE_2D);

    glEnable(GL_LIGHTING);
    GLfloat light_direction[] = { 0.0 , 0.0 , 1.0 };
    GLfloat materialDiffuse[] = { 1.0 , 1.0 , 1.0 , 1.0};
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_direction);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,materialDiffuse);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);

if( LeavingBytes.hasElements() && EnteringBytes.hasElements())
GLInitSlides();//we already have uninitialized slides, let's initialize


    if (pTransition)
        pTransition->prepare ();

.. now, in void OGLTransitionerImpl::setSlides(), we do :

if(GLWin.pOpenGLView)
        GLInitSlides();


.. later in the OpenGL pixel format, we define the OGLFormat as GL_RGB (24 bits). Works corectly, with correct colors



.... in void SAL_CALL OGLTransitionerImpl::update() , we do :

   glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if(pTransition)
    pTransition->display( nTime , GLleavingSlide , GLenteringSlide ,
                              SlideSize.Width, SlideSize.Height,
                              static_cast<double>(GLWin.Width),
                              static_cast<double>(GLWin.Height) );

long swapInt = 1;
[[GLWin.pOpenGLView openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; // set to vbl sync


[[GLWin.pOpenGLView openGLContext] flushBuffer];

if( pWindow )
        pWindow->Show();

... in  void OGLTransitionerImpl::disposing() , we have :

void OGLTransitionerImpl::disposing()
{
    osl::MutexGuard const guard( m_aMutex );
    glDeleteTextures(1,&GLleavingSlide);
    glDeleteTextures(1,&GLenteringSlide);

    if (pTransition)
        pTransition->finish();

if(GLWin.pOpenGLView)
{
[NSOpenGLContext clearCurrentContext];

// the line below triggers the flicker
[GLWin.pOpenGLView removeFromSuperview]; // <--- flicker appears here in debug mode
[GLWin.pOpenGLView release];
GLWin.pOpenGLView = nil;
}
if (pWindow)
delete pWindow;
if (pTransition)
delete pTransition;
}



Could be important: we nill the GLWin.pOpenGLView in the Ctor


Thanks for the one who read until there :-)
--
Education Project: http://wiki.services.openoffice.org/wiki/Education_Project


Blog : http://eric.bachard.free.fr/news

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Preference panes and Apple Help
  • Next by Date: Re: Core Data: Instantiating linked entities
  • Previous by thread: Re: Preference panes and Apple Help
  • Next by thread: Weak Linking & using HiShape
  • Index(es):
    • Date
    • Thread