qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Stewart <peterfs74@gmail.com>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] cocoa.m using openGL
Date: Mon, 23 May 2005 19:31:20 +0200	[thread overview]
Message-ID: <01428d8b1843232b882294c7494a3a45@gmail.com> (raw)

Hi,

It looks faster than the original, but I don't have a benchmark, is  
there one?
I would really like a bootable image with Doom 1 on it.

I also added to Makefile.target, the "-framework OpenGL" bit.

ifdef CONFIG_COCOA
VL_OBJS+=cocoa.o
COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework  
OpenGL
endif



enjoy,
peter.


Here is the diff for cocoa.m ( diff cocoa.m.orig cocoa.m ) (from 0.7.0  
dl):

 > #include <OpenGL/CGLCurrent.h>
 > #include <OpenGL/CGLContext.h>
 >
42,43c45,46
< NSWindow *window = NULL;
< NSQuickDrawView *qd_view = NULL;
---
 > static NSWindow *window = NULL;
 > static NSOpenGLView *ogl_view = NULL;
44a48
 > #define SCREEN_BPP 32
49a54,56
 > GLint screen_tex = 0;
 > GLuint display_list_tex = 0;
 >
64a72
 >
72a81,95
 >
 >       // Make this context current
 >       [[ogl_view openGLContext] makeCurrentContext];
 >
 >       // Bind, update and draw new image
 >       glBindTexture(GL_TEXTURE_RECTANGLE_EXT, screen_tex);
 >
 >       // glTexSubImage2D is faster when not using a texture range
 >       glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA,  
(GLint)ds->width, (GLint)ds->height, 0, GL_BGRA,  
GL_UNSIGNED_INT_8_8_8_8_REV, ds->data);
 >
 >       // Use the compiled display list
 >       glCallList(display_list_tex);
 >
 >       // Swap buffer to screen
 >       [[ogl_view openGLContext] flushBuffer];
74,88d96
<     /* Use QDFlushPortBuffer() to flush content to display */
<     RgnHandle dirty = NewRgn ();
<     RgnHandle temp  = NewRgn ();
<
<     SetEmptyRgn (dirty);
<
<     /* Build the region of dirty rectangles */
<     MacSetRectRgn (temp, x, y,
<                         x + w, y + h);
<     MacUnionRgn (dirty, temp, dirty);
<
<     /* Flush the dirty region */
<     QDFlushPortBuffer ( [ qd_view  qdPort ], dirty );
<     DisposeRgn (dirty);
<     DisposeRgn (temp);
98,100c106
<     const int device_bpp = 32;
<     static void *screen_pixels;
<     static int  screen_pitch;
---
 >
101a108,109
 >
 >     // printf("resizing to %d %d\n", w, h);
103,161c111,139
<     //printf("resizing to %d %d\n", w, h);
<
<     contentRect = NSMakeRect (0, 0, w, h);
<     if(window)
<     {
<         [window close];
<         [window release];
<     }
<     window = [ [ QemuWindow alloc ] initWithContentRect:contentRect
<                                    
styleMask: 
NSTitledWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask
<                                   backing:NSBackingStoreBuffered  
defer:NO];
<     if(!window)
<     {
<         fprintf(stderr, "(cocoa) can't create window\n");
<         exit(1);
<     }
<
<     if(qd_view)
<         [qd_view release];
<
<     qd_view = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ];
<
<     if(!qd_view)
<     {
<          fprintf(stderr, "(cocoa) can't create qd_view\n");
<         exit(1);
<     }
<
<     [ window setAcceptsMouseMovedEvents:YES ];
<     [ window setTitle:@"Qemu" ];
<     [ window setReleasedWhenClosed:NO ];
<
<     /* Set screen to black */
<     [ window setBackgroundColor: [NSColor blackColor] ];
<
<     /* set window position */
<     [ window center ];
<
<     [ qd_view setAutoresizingMask: NSViewWidthSizable |  
NSViewHeightSizable ];
<     [ [ window contentView ] addSubview:qd_view ];
<     [ qd_view release ];
<     [ window makeKeyAndOrderFront:nil ];
<
<     /* Careful here, the window seems to have to be onscreen to do  
that */
<     LockPortBits ( [ qd_view qdPort ] );
<     screen_pixels = GetPixBaseAddr ( GetPortPixMap ( [ qd_view qdPort  
] ) );
<     screen_pitch  = GetPixRowBytes ( GetPortPixMap ( [ qd_view qdPort  
] ) );
<     UnlockPortBits ( [ qd_view qdPort ] );
<     {
<             int vOffset = [ window frame ].size.height -
<                 [ qd_view frame ].size.height - [ qd_view frame  
].origin.y;
<
<             int hOffset = [ qd_view frame ].origin.x;
<
<             screen_pixels += (vOffset * screen_pitch) + hOffset *  
(device_bpp/8);
<     }
<     ds->data = screen_pixels;
<     ds->linesize = screen_pitch;
<     ds->depth = device_bpp;
---
 >     contentRect = NSMakeRect (0, 0, w, h);
 >
 >       [window setContentSize:contentRect.size];
 >       [window update];
 >
 >       [[ogl_view openGLContext] makeCurrentContext];
 >       [[ogl_view openGLContext] update];
 >
 >     glViewport(0, 0, (int) contentRect.size.width, (int)  
contentRect.size.height);
 >
 >       glMatrixMode(GL_PROJECTION);
 >     glLoadIdentity();
 >
 >       glMatrixMode(GL_MODELVIEW);
 >     glLoadIdentity();
 >
 >       // This is used as a init'd flag as well...
 >       if(screen_tex != 0) {
 >               glDeleteTextures(1, &screen_tex);
 >               glDeleteLists(display_list_tex, 1);
 >       }
 >
 >       screen_tex = 1;
 >
 >       if(ds->data != NULL) free(ds->data);
 >       ds->data = (GLubyte *) malloc(w * h * (SCREEN_BPP >> 3));
 >       assert(ds->data != NULL);
 >       ds->linesize = w * (SCREEN_BPP >> 3);
 >     ds->depth = SCREEN_BPP;
164,165c142,195
<
<     current_ds = *ds;
---
 >
 >       // Setup some basic OpenGL stuff as from Apple
 >       glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 >       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 >       glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
 >       glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 >
 >       glEnable(GL_TEXTURE_RECTANGLE_EXT);
 >       glBindTexture(GL_TEXTURE_RECTANGLE_EXT, screen_tex);
 >
 >       glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_EXT,  w * h *  
(SCREEN_BPP >> 3), ds->data);
 >
 >       // Use CACHED for VRAM+reused tex  Use SHARED for AGP+used once  
tex
 >       // Note the texture is always changing so use SHARED
 >       glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,  
GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_SHARED_APPLE);
 >       glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
 >       glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,  
GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 >       glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,  
GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 >       glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S,  
GL_CLAMP_TO_EDGE);
 >       glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T,  
GL_CLAMP_TO_EDGE);
 >       glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
 >
 >       glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, w, h, 0,  
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, ds->data);
 >
 >       glFlush();
 >
 >       // Setup a display list to save all the operations below
 >
 >       display_list_tex = glGenLists(1);
 >       glNewList(display_list_tex, GL_COMPILE);
 >
 >       glBegin(GL_QUADS);
 >
 >       glTexCoord2f(0.0f, 0.0f);
 >       glVertex2f(-1.0f, 1.0f);
 >
 >       glTexCoord2f(0.0f, (GLfloat)h);
 >       glVertex2f(-1.0f, -1.0f);
 >
 >       glTexCoord2f((GLfloat)w, (GLfloat)h);
 >       glVertex2f(1.0f, -1.0f);
 >
 >       glTexCoord2f((GLfloat)w, 0.0f);
 >       glVertex2f(1.0f, 1.0f);
 >
 >       glEnd();
 >
 >       glEndList();
 >
 >
 >       // Swap buffer to screen
 >       [[ogl_view openGLContext] flushBuffer];
 >
 >       memcpy(&current_ds, ds, sizeof(DisplayState));
246d275
<     NSDate *distantPast;
248d276
<     NSAutoreleasePool *pool;
250,253c278,279
<
<     pool = [ [ NSAutoreleasePool alloc ] init ];
<     distantPast = [ NSDate distantPast ];
<
---
 >     NSDate *distantPast = [ NSDate distantPast ];;
 >
255a282
 >
257,258c284,285
<         event = [ NSApp nextEventMatchingMask:NSAnyEventMask  
untilDate:distantPast
<                         inMode: NSDefaultRunLoopMode dequeue:YES ];
---
 >         event = [ window nextEventMatchingMask:NSAnyEventMask  
untilDate:distantPast inMode: NSDefaultRunLoopMode dequeue:YES ];
 >
280a308,309
 >
 >
282,291c311,319
<
<                 case NSLeftMouseDown:
<                 case NSLeftMouseUp:
<
<                 case NSOtherMouseDown:
<                 case NSRightMouseDown:
<
<                 case NSOtherMouseUp:
<                 case NSRightMouseUp:
<
---
 >                                       if(grab)
 >                                       {
 >                                               int dz = [event deltaZ];
 >
 >                                               kbd_mouse_event(0, 0,  
dz, 0);
 >                                       }
 >                                       break;
 >
 >
292a321,332
 >                                       if(grab)
 >                                       {
 >                                               int dx = [event deltaX];
 >                                               int dy = [event deltaY];
 >
 >                                               kbd_mouse_event(dx, dy,  
0, 0);
 >                                       }
 >                                       break;
 >
 >
 >                 case NSOtherMouseDown:
 >                 case NSOtherMouseUp:
293a334,345
 >                                       if(grab)
 >                                       {
 >                                               int dx = [event deltaX];
 >                                               int dy = [event deltaY];
 >                                               int dz = [event deltaZ];
 >
 >                                               kbd_mouse_event(dx, dy,  
dz, MOUSE_EVENT_MBUTTON);
 >                                       }
 >                                       break;
 >
 >                               case NSRightMouseDown:
 >                 case NSRightMouseUp:
294a347,358
 >                                       if(grab)
 >                                       {
 >                                               int dx = [event deltaX];
 >                                               int dy = [event deltaY];
 >                                               int dz = [event deltaZ];
 >
 >                                               kbd_mouse_event(dx, dy,  
dz, MOUSE_EVENT_RBUTTON);
 >                                       }
 >                                       break;
 >
 >                 case NSLeftMouseDown:
 >                 case NSLeftMouseUp:
296,297c360,371
<
<                 default: [NSApp sendEvent:event];
---
 >                                       if(grab)
 >                                       {
 >                                               int dx = [event deltaX];
 >                                               int dy = [event deltaY];
 >                                               int dz = [event deltaZ];
 >
 >                                               kbd_mouse_event(dx, dy,  
dz, MOUSE_EVENT_LBUTTON);
 >                                       }
 >                                       break;
 >
 >                 default:
 >                                       [NSApp sendEvent:event];
300a375
 >
322,324c397,455
<     ds->dpy_update = cocoa_update;
<     ds->dpy_resize = cocoa_resize;
<     ds->dpy_refresh = cocoa_refresh;
---
 >     //printf("resizing to %d %d\n", w, h);
 >
 >       const int w = 640;
 >       const int h = 400;
 >
 >       if(window == nil)
 >       {
 >               // Init pixel format attribs
 >               NSOpenGLPixelFormatAttribute attrs[] =
 >               {
 >                       NSOpenGLPFAAccelerated,
 >                       NSOpenGLPFANoRecovery,
 >                       NSOpenGLPFADoubleBuffer,
 >                       0
 >               };
 >
 >               NSRect contentRect = NSMakeRect (0, 0, w, h);
 >
 >               // Get pixel format from OpenGL
 >               NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat  
alloc] initWithAttributes:attrs];
 >               if (!pixFmt)
 >               {
 >                       fprintf(stderr, "No pixel format -- exiting");
 >                       exit(1);
 >               }
 >
 >               window = [ [ QemuWindow alloc ]  
initWithContentRect:contentRect
 >                                                
styleMask: 
NSTitledWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask
 >                                                
backing:NSBackingStoreBuffered defer:NO];
 >               if(!window)
 >               {
 >                       fprintf(stderr, "(cocoa) can't create  
window\n");
 >                       exit(1);
 >               }
 >
 >               ogl_view = [ [ NSOpenGLView alloc ]  
initWithFrame:contentRect pixelFormat:pixFmt ];
 >
 >               if(!ogl_view)
 >               {
 >                       fprintf(stderr, "(cocoa) can't create  
ogl_view\n");
 >                       exit(1);
 >               }
 >
 >               [ window setAcceptsMouseMovedEvents:YES ];
 >               [ window setTitle:@"Qemu" ];
 >               [ window setReleasedWhenClosed:NO ];
 >
 >               /* set window position */
 >               [ window center ];
 >               [ window makeKeyAndOrderFront:nil ];
 >
 >               [ ogl_view setAutoresizingMask: NSViewWidthSizable |  
NSViewHeightSizable ];
 >               [ window setContentView:ogl_view ];
 >               [ ogl_view release ];
 >       }
 >
 >       ds->dpy_update = cocoa_update;
 >       ds->dpy_resize = cocoa_resize;
 >       ds->dpy_refresh = cocoa_refresh;
327c458,462
<
---
 >
 >       [ window display ];
 >       [ window makeMainWindow ];
 >       [ window makeKeyWindow ];
 >
344,359c479
< static void QZ_SetPortAlphaOpaque ()
< {
<     /* Assume 32 bit if( bpp == 32 )*/
<     if ( 1 ) {
<
<         uint32_t    *pixels = (uint32_t*) current_ds.data;
<         uint32_t    rowPixels = current_ds.linesize / 4;
<         uint32_t    i, j;
<
<         for (i = 0; i < current_ds.height; i++)
<             for (j = 0; j < current_ds.width; j++) {
<
<                 pixels[ (i * rowPixels) + j ] |= 0xFF000000;
<             }
<     }
< }
---
 >
365,367c485
<     /* make the alpha channel opaque so anim won't have holes in it */
<     QZ_SetPortAlphaOpaque ();
<
---
 >     /* make the alpha channel opaque so anim won't have holes in it */
380,382c498
<
<     /* make sure pixels are fully opaque */
<     QZ_SetPortAlphaOpaque ();
---
 >
385c501
<     [ self cacheImageInRect:[ qd_view frame ] ];
---
 >     [ self cacheImageInRect:[ ogl_view frame ] ];
427,428c543,544
<         cocoa_resize(&current_ds, 640, 400);
<
---
 >               cocoa_display_init(&current_ds, 0);
 >
451a568,572
 >
 >
 >
 >
 >
454c575,577
<     if(returnCode == NSCancelButton)
---
 >       [sheet close];
 >
 >       if(returnCode == NSCancelButton)

             reply	other threads:[~2005-05-23 18:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-23 17:31 Peter Stewart [this message]
2005-05-23 19:17 ` [Qemu-devel] cocoa.m using openGL Mike Kronenberg
2005-05-23 21:54   ` Hetz Ben Hamo
  -- strict thread matches above, loose matches on Subject: below --
2005-05-23 23:58 Peter Stewart
2005-05-23 23:31 Peter Stewart
2005-05-24  0:20 ` Mike Kronenberg
2005-05-23 23:29 Peter Stewart
2005-05-23  7:47 Peter Stewart
2005-05-23  8:38 ` Mike Kronenberg
2005-05-22 13:00 Peter Stewart
2005-05-22 13:45 ` Hetz Ben Hamo
2005-05-23  7:20 ` Mike Kronenberg
2005-05-24 15:11 ` Mike Kronenberg
2005-05-26 15:09   ` Pierre d'Herbemont
2005-05-27 14:57   ` Pierre d'Herbemont
2005-05-28 18:39     ` Mike Kronenberg
2005-05-29 14:47       ` Pierre d'Herbemont
2005-05-26 14:52 ` Pierre d'Herbemont

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01428d8b1843232b882294c7494a3a45@gmail.com \
    --to=peterfs74@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).