bugGNUstep - Bugs: bug #25548, NSOpenGLContext can't...

Group
 
 

bug #25548: NSOpenGLContext can't -makeCurrentContext independently of NSOpenGLView.

Submitter:  matt rice <ratmice>
Submitted:  Tue 10 Feb 2009 05:10:24 PM UTC
   
 
Category:  Backend Severity:  2 - Minor
Item Group:  None Status:  Ready For Test
Privacy:  Public Assigned to:  _57132
Open/Closed:  In Test
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

  Spam posted by _200460
  Spam posted by _178561
Wed 01 Apr 2009 02:02:57 PM UTC, comment #8: 

I've just tested Matt's contextTest v1 and v2 on Mac OSX 10.4:

  • V1 does not output any message, but this does not mean it does something. An extended test might help.
  • V2 is (almost) ok : I think my patch might be port to Win32 and added to the official backend, as it's a improvement in compatibility.


Matt : did you test my patch along with my suggestions in your project ?


- <_57132>
Sat 07 Mar 2009 05:27:18 PM UTC, comment #7: 

Here is a enhanced version of your contextTest. It demonstrates that my patch is not so bad. I tried to mimic your needs but as i don't know anything about nib file it needs some work.

(file #17612)

- <_57132>
Fri 06 Mar 2009 10:43:46 PM UTC, comment #6: 

yes, I know (and I assume you meant NSOpenGLContext -initWithFormat:sharedContext:)

that was a big reason why the patch was a hack, it was just easier for the moment the idea was to do this in -makeCurrentContext

which will give the caller time to configure the context, but that is easier said than done and going to require quite a bit of rework.

matt rice <ratmice>
Group Member
Fri 06 Mar 2009 07:34:11 PM UTC, comment #5: 

You can not create a sub-window in [GLView -initWithFormat...] because you don't even know if the context will draw to a window. It might draw fullscreen, or to a pixmap, or to a pixel buffer. You can not know before [-setView:] or [-setFullscreen], etc.

But you can reparent a NSOpenGLView. As i said, the current (partial and not tested) implementation destroy the glx context, that will be re-create on the new window by the next [-openGLContext]. This (simple) behavior might be wrong.

Please check the attached patches to the current trunk version. You should then be able to reparent an NSOpenGLView without the context to be destroyed.
1. create the view [-initWithFrame:...] in an unmap or hidden window
2a. get the context and initialize your renderer
2b. load your nib file
3. add the view to your brand new window [-addSubview:]




(file #17606, file #17607)

- <_57132>
Fri 06 Mar 2009 04:01:39 PM UTC, comment #4: 

here's a hack of a patch which implements this, works with my test & MyGL and my program, it'll need lots cleaning up

Yeah, i know we need a drawable, but the drawable and the NSView are relatively unrelated except they must share a display.

the views window must be the contexts parent to be displayed in the right place, we can create the drawable before we are attached to an NSView and then reparent it to get the view to draw in the right place...

theres a few ways to work around this, create the windows offscreen on application load
this doesn't help me really, because one of the problems i've run into is that things like NSOutlineView call -reloadData in initWithCoder: which makes writing my dataSources a pain since I have to write checks in every method to see if openGL has been initialized yet, because a call to the renderer before it is initialized will crash it,

the other option is using multiple nib files, this involves creating an NSBox and replacing those for every view which shares a window with my nib, besides that I can't actually look at what my window will look like.

and I cannot change the context after initialization.

I really don't think that there is any proof that the test attached to this bug shouldn't work, and it isn't documented as not working, and this patch should show that it isn't impossible.... anyhow yes, I know it could be worked around but none of those options really appeal to me

(and fwiw I don't really care if it isn't portable because hacking the renderer to use glxGetCurrentContext isn't portable either).


(file #17599)

matt rice <ratmice>
Group Member
Fri 06 Mar 2009 08:35:46 AM UTC, comment #3: 

Incidentally I found a small bug in XGGLFormat. But this has nothing to do with your problem :/

You cannot 'makeCurrent' a context that has not been attached to a drawable, ie with [-setView:]. This is not a bug. You probably can not do that even with glx functions.

If your renderer needs a drawable or a context to initialize itself, then you have to wait for the View to be ready. I'm afraid you can not even create programmatically your GLView, then re-parent it when your nib window is ready, because the current implementation destroys the context when the view is moved to an other window (this is new, not tested and may not be Cocoa-compatible)

Some suggestions :

  • You may insert your NIB file in a programmatically created window that contains a GLView. (dunno how to do that!)
  • Split your NIB file : 1st load the GLView part, then initialize your renderer, then load the remaining NIB.
  • If you can change the context of your renderer after initialization, you may initialize it with a dummy context.


Hope this will help...

- <_57132>
Fri 06 Mar 2009 01:08:40 AM UTC, comment #2: 

attached is a test program that shows what i'd like to do...

the problem being i'm drawing into NSOpenGLView using external renderer which in turn uses

glxGetCurrentDrawable/glxGetCurrentContext

initialization of the external renderer takes a bit of time, so i'd rather do it at startup rather than waiting to initialize the renderer until I open the nib file which contains the NSOpenGLView

I don't have any code which says that it should work, but there is nothing in the documentation which leads me to believe that it shouldn't work.


this page leads me to believe that NSOpenGLContext is usable outside of NSOpenGLView though.

http://www.mikeash.com/?page=pyblog/nsopenglcontext-and-one-shot.html

so yeah, i don't know if this code should work, but it doesn't.


(file #17594)

matt rice <ratmice>
Group Member
Thu 05 Mar 2009 11:04:05 AM UTC, comment #1: 

The current GNUstep implementation allows only 'windowed context' (defined with [-setView]). 'Off screen' and 'fullscreen' contexts will be implemented sooner or later, and dont need any view or sub-window.

I dont know many about shared contexts. They look te be handled fine in XGGLFormat.m

Could you please post some code that should work but does not ? Thanks!

- <_57132>
Tue 10 Feb 2009 05:10:24 PM UTC, original submission:  

i'm thinking this might be possible if we create the x window stuff currently in XGXSubWindow in the NSOpenGLContext and then on -setView: call XReparentWindow, instead of delaying until we have a parent to create the XGXSubWindow for..

the -openGLContextWithShareContext: method here does this...

http://developer.apple.com/DOCUMENTATION/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/chapter_7_section_4.html#//apple_ref/doc/uid/TP40001987-CH216-SW7


matt rice <ratmice>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #17612:  contextTest-0.0.2.tar.gz added by _57132 (1KiB - application/octetstream)
file #17606:  back.diff added by _57132 (828B - text/x-diff)
file #17607:  gui.diff added by _57132 (1KiB - text/x-diff)
file #17599:  foo.diff added by ratmice (7KiB - application/octet-stream)
file #17594:  contextTest-0.0.1.tar.gz added by ratmice (667B - application/x-gzip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by _200460 (Posted a comment)
  • -email is unavailable- added by _178561 (Posted a comment)
  • -email is unavailable- added by _57132 (Posted a comment)
  • -email is unavailable- added by ratmice (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-03-07 _57132 Attached File- Added contextTest-0.0.2.tar.gz, #17612
    2009-03-06 _57132 Attached File- Added back.diff, #17606
        Attached File- Added gui.diff, #17607
        Severity3 - Normal 2 - Minor
        StatusInvalid Ready For Test
        Assigned toNone _57132
        Open/ClosedAnalyzed In Test
    2009-03-06 ratmice Attached File- Added foo.diff, #17599
    2009-03-06 _57132 Item GroupBug None
        StatusNone Invalid
        Open/ClosedOpen Analyzed
    2009-03-06 ratmice Attached File- Added contextTest-0.0.1.tar.gz, #17594

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code