NSOpenGLView - forcing an update.

  • Hello List,

    I would like to know how I can force a bog standard NSOpenGLView to
    refresh its content.  Is it as simple as saying :
    [theView setNeedsDisplay:YES]

    ???

    Cos when I do this, my draw method does get called (i.e. drawRect:),
    but the image on the view itself does not change.  When I resize the
    view, the image is then updated immediately.  Anyone else seen this
    kinda of thing before?

    Thanks (a lot) in advance for any comments/help - have a good day!
    --
    John Clayton
  • On 23 Nov 2007, at 09:08, John Clayton wrote:

    > I would like to know how I can force a bog standard NSOpenGLView to
    > refresh its content.  Is it as simple as saying :
    > [theView setNeedsDisplay:YES]
    >
    > ???
    >
    > Cos when I do this, my draw method does get called (i.e. drawRect:),
    > but the image on the view itself does not change.  When I resize the
    > view, the image is then updated immediately.  Anyone else seen this
    > kinda of thing before?

    Is your NSOpenGLView double-buffered?  If so, are you calling the -
    flushBuffer method at appropriate times?

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
  • Alistair,

    Thanks - I've found something interesting.

    The custom NSOpenGLView was NOT specified as being double-buffered in
    the NIB.

    I changed it to be double buffered, and then re-ran the program and
    the behaviour is now:

    - on startup, moving my slider back and forth does not refresh the
    video frame.

    - if I then resize the window, and then move the slider - everything
    works PERFECTLY.

    the drawRect: looks like this:

    - (void)drawRect:(NSRect)r
    {
    if(_textureContext == 0)
      return;

    float w = self.frame.size.width;
    float h = self.frame.size.height;

    // the movie is already positioned... just get the current frame.
    CVImageBufferRef imageBuffer = 0;
    QTVisualContextCopyImageForTime(_textureContext,
            kCFAllocatorDefault,
            0,
            &imageBuffer);

    NSRect rect = NSMakeRect(0, 0, w, h);
    CIImage* theImage = 0;

    if(imageBuffer)
    {
      theImage = [CIImage imageWithCVImageBuffer:imageBuffer];
      CGSize cgTexSize = CVImageBufferGetDisplaySize(imageBuffer);
      rect = rectAdjustedToAspectRatio(NSMakeRect(0, 0, w, h),
                                            NSMakeSize(cgTexSize.width, cgTexSize.height));

      CVBufferRelease(imageBuffer);
      imageBuffer = 0;

      [_ciContext drawImage: theImage
                         inRect: NSRectToCGRect(rect)
                        fromRect: [theImage extent]];
    }

    // thanks to Alistair!
    [[self openGLContext] flushBuffer];

    // ensures that the context can free released resources regularly
    QTVisualContextTask(_textureContext);
    }

    so I basically need to force a resize and then things work great after
    that.

    BTW: I set up the view outlet by placing an NSOpenGLView on the NIB,
    and then setting the type of that view to my GLRenderView class, and
    then I have the following properties:
    - double buffer
    - accelerated rendering
    - no recovery

    everything else is defaulted.

    any ideas as to what this odd startup bug might be?

    Thanks for the tip - very nice.

    --
    john clayton

    On 23/11/2007, at 12:03 PM, Alastair Houghton wrote:

    > On 23 Nov 2007, at 09:08, John Clayton wrote:
    >
    >> I would like to know how I can force a bog standard NSOpenGLView to
    >> refresh its content.  Is it as simple as saying :
    >> [theView setNeedsDisplay:YES]
    >>
    >> ???
    >>
    >> Cos when I do this, my draw method does get called (i.e.
    >> drawRect:), but the image on the view itself does not change.  When
    >> I resize the view, the image is then updated immediately.  Anyone
    >> else seen this kinda of thing before?
    >
    > Is your NSOpenGLView double-buffered?  If so, are you calling the -
    > flushBuffer method at appropriate times?
    >
    > Kind regards,
    >
    > Alastair.
    >
    > --
    > http://alastairs-place.net
    >
    >
  • On 23 Nov 2007, at 11:13, John Clayton wrote:

    > Thanks - I've found something interesting.
    >
    > The custom NSOpenGLView was NOT specified as being double-buffered
    > in the NIB.
    >
    > I changed it to be double buffered, and then re-ran the program and
    > the behaviour is now:
    >
    > - on startup, moving my slider back and forth does not refresh the
    > video frame.
    >
    > - if I then resize the window, and then move the slider - everything
    > works PERFECTLY.

    Where are you setting up your projection and/or viewport?  It could be
    that it isn't happening until the view gets resized for some reason.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
  • SEMI SOLVED: i.e. I'm gonna stop.

    Just for the list - I recompiled my spike solution so it runs on
    Tiger, and lo and behold - it ran perfectly.  So I've filed a bug at
    Apple, including my little .mov file and the program, demonstrating
    the problem that 10.5.1 exhibits with the same code.

    --
    John Clayton
    http://www.coderage-software.com/

    On 23/11/2007, at 12:28 PM, Alastair Houghton wrote:

    > On 23 Nov 2007, at 11:13, John Clayton wrote:
    >
    >> Thanks - I've found something interesting.
    >>
    >> The custom NSOpenGLView was NOT specified as being double-buffered
    >> in the NIB.
    >>
    >> I changed it to be double buffered, and then re-ran the program and
    >> the behaviour is now:
    >>
    >> - on startup, moving my slider back and forth does not refresh the
    >> video frame.
    >>
    >> - if I then resize the window, and then move the slider -
    >> everything works PERFECTLY.
    >
    >
    > Where are you setting up your projection and/or viewport?  It could
    > be that it isn't happening until the view gets resized for some
    > reason.
    >
    > Kind regards,
    >
    > Alastair.
    >
    > --
    > http://alastairs-place.net
    >
    >
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today