Single buffered window

Member
Posts: 81
Joined: 2007.07
Post: #1
Hello everyone, I am working on my first mac game and everything is up and running smoothly for me, I bought an Intel Core Duo and my game is running 1024x768x32 at around 50fps (triple buffered) using my own software engine. I have tried a couple ways to blit my screen and am currently using CopyBits and QDFlushPortBuffer. This was clocking in at around 11ms, I then went the extra mile and threaded it and got it down to around 8.5ms. I have also tried using GLUT to copy my buffer, and it clocks in at around 7ms (using glDrawPixels). I'm guessing the reason CopyBits is slightly slower is because OSX is double buffering the window and doing an extra copy, now finally my question Smile

Does anyone one know how I can request that my window only be single buffered?

I am assuming this is possible because of a statement here "All drawing into windows in Mac OS X is double-buffered unless you explicitly request otherwise."
http://tuvix.apple.com/documentation/Per...awing.html

I can post my current window creation code, blitting code, or anything else you might want to see, its all pretty basic stuff though.
_hwnd = NewCWindow(nil, &r, "\p ", true, noGrowDocProc, (WindowPtr)-1, true, 0);
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #2
It would be good to know what kinda rendering you are doing. glDrawPixels is still notoriously slow, using your rendered image as a real OpenGL texture is probably the fastest way to get it on-screen. Also, why are you using triple buffering?

As for your buffering problem, you should be using CreateNewWindow instead of the legacy NewCWindow.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
Quote this message in a reply
Member
Posts: 81
Joined: 2007.07
Post: #4
DoG: The window is triple buffered right now because I have one internal buffer I blit to (I have to because the CopyBits buffers pitch size is greater than its width, and my custom 2d engine doesn't support that), and the other 2 buffers just the default Mac OSX buffers for the window.

I looked over CreateNewWindow and didn't see anything in the windowClass or attributes parameters that said anything about requesting a single buffered window, so I'm not sure how that function would help me?

arekkusu: That is a great reference, thanks, perhaps I should just try a glTexSubimage implementation and see how fast that is, the reason I didn't is because once I got glDrawPixels running it seemed really fast, I think it works great on my Duo, but I think it is garbage on anything older, as I had someone test on an eMac and it wasn't working too well.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #5
If you use textures, be sure to remember that it needs to be powers of 2. (unless you chose to use rectangular textures) It's still copying a lot of data over, though, so it would still be slow. The ideal way (as far as speed goes) will be to load all your textures in the beginning and then map them to quads. However, that would likely need a complete engine rewrite on your part.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #6
akb825 Wrote:It's still copying a lot of data over, though, so it would still be slow.
Yeah, but glTexSubimage is still the fastest show in town for getting a software frame buffer to screen on OS X, and using rectangle textures is the fastest that I've found. Using glTexSubimage can allow DMA transfers, so as to bypass the CPU altogether -- how are you going to beat that (except for as you pointed out, doing everything from the sprite level up on quads)? I don't know of any other hardware accelerated rasterization method on OS X.

Rasterman, since you're new, and just so's ya know, arekkusu and OneSadCookie are regarded as the two most knowledgable graphics guys here. I'm only saying that right now to highlight arekkusu's advice above, but generally you can count on it.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
akb825 Wrote:If you use textures, be sure to remember that it needs to be powers of 2. (unless you chose to use rectangular textures) It's still copying a lot of data over, though, so it would still be slow. The ideal way (as far as speed goes) will be to load all your textures in the beginning and then map them to quads. However, that would likely need a complete engine rewrite on your part.

Please read the tutorial before commenting on it, it addresses all of these issues.

DMA'd texsubimage is the fast path (optimized for the window server, QuickTime, etc etc.)
Quote this message in a reply
Member
Posts: 81
Joined: 2007.07
Post: #8
Results: The fastest I got glTexSubImage2D working was at 5.1ms using GL_TEXTURE_RECTANGLE_EXT at 1024x768x32. I tried using GL_UNSIGNED_INT_8_8_8_8 and GL_UNPACK_CLIENT_STORAGE_APPLE but I couldn't get either working. This turns out to be about 600 MB/s, my memory is 667MHz DDR2, so maybe the theoretical bandwidth I should be getting could be calculated. At any rate this isn't too much faster than my 8.5ms CopyBits code (which includes a 2.5ms third buffer copy that I could get rid of if I tweaked my internal 2d engine).

By the way does anyone know the answer to the original question? How can I make OSX not double buffer my window?
Quote this message in a reply
Member
Posts: 21
Joined: 2007.09
Post: #9
arekkusu Wrote:Do this: http://developer.apple.com/samplecode/Te...Range.html



I spent a bit of time figuring out how to use ImageIO instead of NSImageBitmap Representation and now I see this method of texture loading from the apple texture range tutorial.

Question: Why doesn't this method seem to recognize my alpha channel. Do I need something analogous to this?

Code:
    CGContextRef context = CGBitmapContextCreate(data, width, height, 8,width * 4,
     color_space, kCGImageAlphaPremultipliedFirst);

Where would that even go since I don't even see a core graphics context being created (just an offscreen Gworld)?

What are the pros and cons of loading the images into a buffer then taking them from the buffer to the textures anyway?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #10
MikeC Wrote:I spent a bit of time figuring out how to use ImageIO instead of NSImageBitmap Representation and now I see this method of texture loading from the apple texture range tutorial.

Question: Why doesn't this method seem to recognize my alpha channel. Do I need something analogous to this?

Code:
    CGContextRef context = CGBitmapContextCreate(data, width, height, 8,width * 4,
     color_space, kCGImageAlphaPremultipliedFirst);

Where would that even go since I don't even see a core graphics context being created (just an offscreen Gworld)?

The code above looks OK. When you call CGContextDrawImage, ImageIO writes to the pointer you passed as the first parameter to CGBitmapContextCreate, which you'd first malloc to be large enough to contain width * height * 4. Once you've drawn the image into your buffer, you can release the bitmap context and do whatever you need to with the pixel data.

MikeC Wrote:What are the pros and cons of loading the images into a buffer then taking them from the buffer to the textures anyway?

As opposed to...?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Changing Uniform Variables for a Single Shader reapz 3 5,615 Jul 15, 2010 01:29 AM
Last Post: dazza
  Texture mapping single 3D object with one draw call jeonghyunhan 1 2,803 Jul 13, 2009 06:05 AM
Last Post: ThemsAllTook
  Copying from OpenGL window to other window Ingemar 7 4,913 Nov 4, 2006 03:50 AM
Last Post: OneSadCookie
  glTexImage2D() and single colour component textures sealfin 3 4,691 Aug 10, 2004 04:45 AM
Last Post: arekkusu
  Apply rotation to a single vertex LongJumper 8 4,193 Jul 14, 2004 02:34 AM
Last Post: kberg