Skip to contentSkip to conversation

cocoa.m using openGL

Qemu-devel Peter Stewart 3 participants 3 messages May 23, 2005

lore
Share & tools
lore
#0 lore 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):

Quoted 3 lines

#include <OpenGL/CGLCurrent.h>
#include <OpenGL/CGLContext.h>

42,43c45,46
< NSWindow *window = NULL;
< NSQuickDrawView *qd_view = NULL;
---

Quoted 2 lines

static NSWindow *window = NULL;
static NSOpenGLView *ogl_view = NULL;

44a48

Quoted 1 line

#define SCREEN_BPP 32

49a54,56

Quoted 3 lines

GLint screen_tex = 0;
GLuint display_list_tex = 0;

64a72

Quoted 1 line

72a81,95

Quoted 15 lines
      // 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;

---

Quoted 1 line

101a108,109

Quoted 2 lines
    // 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;

---

Quoted 22 lines
    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);
      }
Quoted 7 lines
      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;
---

Quoted 47 lines
      // 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();
Quoted 7 lines
      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 ];
<
---

Quoted 2 lines
    NSDate *distantPast = [ NSDate distantPast ];;

255a282

Quoted 1 line

257,258c284,285
< event = [ NSApp nextEventMatchingMask:NSAnyEventMask untilDate:distantPast
< inMode: NSDefaultRunLoopMode dequeue:YES ];
---

Quoted 2 lines
        event = [ window nextEventMatchingMask:NSAnyEventMask untilDate:distantPast inMode: NSDefaultRunLoopMode dequeue:YES ];

280a308,309

Quoted 2 lines

282,291c311,319
<
< case NSLeftMouseDown:
< case NSLeftMouseUp:
<
< case NSOtherMouseDown:
< case NSRightMouseDown:
<
< case NSOtherMouseUp:
< case NSRightMouseUp:
<
---

Quoted 9 lines
                                      if(grab)
                                      {
                                              int dz = [event deltaZ];

                                              kbd_mouse_event(0, 0, dz, 0);
                                      }
                                      break;

292a321,332

Quoted 5 lines
                                      if(grab)
                                      {
                                              int dx = [event deltaX];
                                              int dy = [event deltaY];
Quoted 7 lines
                                              kbd_mouse_event(dx, dy, 0, 0);
                                      }
                                      break;


                case NSOtherMouseDown:
                case NSOtherMouseUp:

293a334,345

Quoted 4 lines
                                      if(grab)
                                      {
                                              int dx = [event deltaX];
                                              int dy = [event deltaY];
Quoted 8 lines
                                              int dz = [event deltaZ];

                                              kbd_mouse_event(dx, dy, dz, MOUSE_EVENT_MBUTTON);
                                      }
                                      break;

                              case NSRightMouseDown:
                case NSRightMouseUp:

294a347,358

Quoted 4 lines
                                      if(grab)
                                      {
                                              int dx = [event deltaX];
                                              int dy = [event deltaY];
Quoted 8 lines
                                              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];
---

Quoted 4 lines
                                      if(grab)
                                      {
                                              int dx = [event deltaX];
                                              int dy = [event deltaY];
Quoted 8 lines
                                              int dz = [event deltaZ];

                                              kbd_mouse_event(dx, dy, dz, MOUSE_EVENT_LBUTTON);
                                      }
                                      break;

                default:
                                      [NSApp sendEvent:event];

300a375

Quoted 1 line

322,324c397,455

<     ds->dpy_update = cocoa_update;
<     ds->dpy_resize = cocoa_resize;
<     ds->dpy_refresh = cocoa_refresh;

---

Quoted 51 lines
    //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 ];
Quoted 8 lines
              [ 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
<
---

Quoted 5 lines
      [ 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;
< }
< }
< }
---

Quoted 1 line

365,367c485
< /* make the alpha channel opaque so anim won't have holes in it */
< QZ_SetPortAlphaOpaque ();
<
---

Quoted 1 line
    /* make the alpha channel opaque so anim won't have holes in it */

380,382c498
<
< /* make sure pixels are fully opaque */
< QZ_SetPortAlphaOpaque ();
---

Quoted 1 line

385c501
< [ self cacheImageInRect:[ qd_view frame ] ];
---

Quoted 1 line
    [ self cacheImageInRect:[ ogl_view frame ] ];

427,428c543,544
< cocoa_resize(&current_ds, 640, 400);
<
---

Quoted 2 lines
              cocoa_display_init(&current_ds, 0);

451a568,572

Quoted 5 lines

454c575,577
< if(returnCode == NSCancelButton)
---

Quoted 3 lines
      [sheet close];

      if(returnCode == NSCancelButton)
#1 lore raw
Quoted 4 lines · Peter Stewart

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.

http://www.kberg.ch/cocoaqemu/files/freedosdoom.img.zip
have fun

Quoted 1 line

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

Somehow, I cant patch it to cocoa.m
could you post cocoa.m as a attachement, since i have not alot in common with cocoa.m animore :)

Mike

#2 lore raw

Could you use diff -u please? that surely could help.

Thanks,
Hetz

Quoted 27 lines · Mike Kronenberg
Quoted 5 lines · Peter Stewart

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.

http://www.kberg.ch/cocoaqemu/files/freedosdoom.img.zip
have fun

Quoted 2 lines

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

Somehow, I cant patch it to cocoa.m
could you post cocoa.m as a attachement, since i have not alot in common with cocoa.m animore :)

Mike

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel