Professional Web Applications Themes

Trying again: Buffer swapping and MacOS X - Mac Programming

Hey I have asked this question before (quite a while ago), but I am hoping someone new to the group has an answer, or maybe there are new features in Panther to solve it. Anyway, gere goes: Is there a way to perform hardware buffer swapping (fullscreen graphics) in MacOS X? Hardware buffer swapping means that you draw to a back buffer, and then switch the buffers, so that the back buffer becomes the front buffer, and you obtain a new pointer to a new back buffer. If it's not true hardware buffering, the back buffer is instead *copied* to ...

  1. #1

    Default Trying again: Buffer swapping and MacOS X

    Hey

    I have asked this question before (quite a while ago), but I am hoping
    someone new to the group has an answer, or maybe there are new features
    in Panther to solve it. Anyway, gere goes:

    Is there a way to perform hardware buffer swapping (fullscreen graphics)
    in MacOS X?

    Hardware buffer swapping means that you draw to a back buffer, and then
    switch the buffers, so that the back buffer becomes the front buffer,
    and you obtain a new pointer to a new back buffer. If it's not true
    hardware buffering, the back buffer is instead *copied* to the front
    buffer, which is slower and often look less smooth.

    The reason I'm asking is because I want to make a 2D jump-n-run game,
    and since it will require frequent updating of the whole screen
    (horizontal scrolling), I believe buffer swapping is the best way to
    make it smooth.

    OpenGL supports hardware buffer swapping, but can't be used, because
    OpenGL is for 3D. I have tried bitmap graphics with OpenGL, it goes
    slooooow, probably because it needs to perform a lot of pixel
    transformations I don't really need. When working with 2D bitmap
    graphics, it's better to gain direct access to the frame buffer.

    DrawSprockets (or was it GameSprockets) has a swap buffers command, but
    DS is buggy on OS X, and the implementation only COPIES the buffer
    rather than SWAP them.

    I'd like to stick to Cocoa, Objective-C or C, but if it requires me to
    look at Carbon/QuickDraw... I will bite the bullet and do it... :-/

    (Sorry for not posting to comp.sys.mac.programmer.games, but the group
    seems practically dead...)

    Per
    Per Guest

  2. #2

    Default Re: Trying again: Buffer swapping and MacOS X

    In article <1g62a7y.1hofggwok539gN%com>,
    com (Per Bull Holmen) wrote:
     

    Yes. OpenGL
     

    2D is just 3D with the Z-coordinate set to zero and using orthog
    projection. Sprite graphics is trivial using textures with alpha channel
    texture-mapped onto rectangles.

    If you are just drawing one rectangle, the size of the screen, textured
    from an offscreen GWorld, located on the video card, into which you have
    drawn with Quickdraw, it is very fast. (Use two and swap between them.)

    I allocate a full screen GL context, and sync it to the video for that
    CRT (no point rendering frames faster than the hardware can show them)
    and run it from a Multiprocessing.h MPThread.

    You've got a very powerful processor in the video card. Use it. Use
    OpenGL.
    David Guest

  3. #3

    Default Re: Trying again: Buffer swapping and MacOS X

    In article <1g62a7y.1hofggwok539gN%com>,
    com (Per Bull Holmen) wrote:
     

    Maybe the terminology has changed since my experiments with writing a
    tile-based game engine, but what you describe as "hardware buffer
    swapping" is actually called page flipping. Assuming there's enough
    VRAM, you draw an image into one half of memory and tell the video card
    to display it, then draw the next image into the other half of memory
    and, when done, tell the video card to draw that instead.

    If you search the apple developer site for "page flipping" you'll
    probably get more relevant results.

    --
    |\/| /| |2 |<
    mehaase(at)sas(dot)upenn(dot)edu
    Mark Guest

  4. #4

    Default Re: Trying again: Buffer swapping and MacOS X

    Mark Haase <net> wrote:
     

    Ahhhh.... thanks for telling me....

    You are right, it's called page flipping. I was searching my head for
    the correct term, which I used to know, I must have been suffering from
    a temporary "mind block"... :)

    Earlier I have tried to find any info on "page flipping" on the Apple
    site, with poor results. I'll try again now. Thank you!!!

    Per
    Per Guest

  5. #5

    Default Re: Trying again: Buffer swapping and MacOS X

    David Phillip Oster <org> wrote:
     
    >
    > Yes. OpenGL

    >
    > 2D is just 3D with the Z-coordinate set to zero and using orthog
    > projection. Sprite graphics is trivial using textures with alpha channel
    > texture-mapped onto rectangles.
    >
    > If you are just drawing one rectangle, the size of the screen, textured
    > from an offscreen GWorld, located on the video card, into which you have
    > drawn with Quickdraw, it is very fast. (Use two and swap between them.)[/ref]

    I'm no good with QuickDraw and GWorlds, I'm a Cocoa man, but I assume
    what matters is that the image data has the same format as the 'native'
    format in the frame buffer? Also, I'd like to know if there's any other
    way than QD to have an offscreen buffer located on the video card.
     

    My earlier experience with OpenGL for bitmap graphics was making a
    slideshow, with a gradual blending transition from one image to another
    (1024x768, 24bit). I found OpenGL to do the job much slower than Quartz,
    which again did it way slower than my final solution, using Altivec
    drawing directly to the frambuffer.

    I may have done something wrong with OpenGL, I find it oh so POWERFUL,
    but maybe a bit too powerful because it has so many advanced features I
    don't need. I try to remember to switch off every little thing that I'm
    not using, but I can never know if there's something I have forgotten,
    or if I could do the job faster using other OpenGL functions etc. What
    matters though, are the results, and I haven't achieved as good results
    with plain bitmap as doing it "by hand".

    Per
    Per Guest

  6. #6

    Default Re: Trying again: Buffer swapping and MacOS X

    David Phillip Oster <org> wrote:
     
    >
    > Yes. OpenGL

    >
    > 2D is just 3D with the Z-coordinate set to zero and using orthog
    > projection. Sprite graphics is trivial using textures with alpha channel
    > texture-mapped onto rectangles.
    >
    > If you are just drawing one rectangle, the size of the screen, textured
    > from an offscreen GWorld, located on the video card, into which you have
    > drawn with Quickdraw, it is very fast. (Use two and swap between them.)[/ref]

    I'm no good with QuickDraw and GWorlds, I'm a Cocoa man, but I assume
    what matters is that the image data has the same format as the 'native'
    format in the frame buffer? Also, I'd like to know if there's any other
    way than QD to have an offscreen buffer located on the video card.
     

    My earlier experience with OpenGL for bitmap graphics was making a
    slideshow, with a gradual blending transition from one image to another
    (1024x768, 24bit). I found OpenGL to do the job much slower than Quartz,
    which again did it way slower than my final solution, using Altivec
    drawing directly to the frambuffer.

    I may have done something wrong with OpenGL, I find it oh so POWERFUL,
    but maybe a bit too powerful because it has so many advanced features I
    don't need. I try to remember to switch off every little thing that I'm
    not using, but I can never know if there's something I have forgotten,
    or if I could do the job faster using other OpenGL functions etc. What
    matters though, are the results, and I haven't achieved as good results
    with OpenGL when working with plain bitmap as doing it "by hand"
    directly to the frame buffer.

    Per
    Per Guest

  7. #7

    Default Re: Trying again: Buffer swapping and MacOS X

    In article <1g62xyu.d1k1kr1dk5vxiN%com>,
    com (Per Bull Holmen) wrote:
     

    You know that there are already optimized system calls for that:

    <http://www.apple.com/quicktime/samples/effects/#trans>

    and:

    <http://developer.apple.com/doentation/quicktime/RM/EffectsTransitions
    /Effects/index.html>

    and

    <http://developer.apple.com/doentation/quicktime/RM/EffectsTransitions
    /Effects/index.html>
    David Guest

  8. #8

    Default Re: Trying again: Buffer swapping and MacOS X

    David Phillip Oster <org> wrote:
     
    >
    > You know that there are already optimized system calls for that:
    >
    > <http://www.apple.com/quicktime/samples/effects/#trans>
    >
    > and:
    >
    > <http://developer.apple.com/doentation/quicktime/RM/EffectsTransitions
    > /Effects/index.html>
    >
    > and
    >
    > <http://developer.apple.com/doentation/quicktime/RM/EffectsTransitions
    > /Effects/index.html>[/ref]

    Thanks. Now I have a lot of new effects for the slideshow app.

    The Altivec function I made was so smooth on very high resolutions and
    bit depth, it's impossible to see that it's not actually "linear" so to
    speak. So I'll keep it.

    Thanks for all your help, it reminds me I should use this group a little
    more often!!! :)

    I'll try your OpenGL solution for my game, learning Quicktime I will
    have to postpone... so much stuff to learn, but so much to benefit... :)

    Per
    Per Guest

  9. #9

    Default Re: Trying again: Buffer swapping and MacOS X

    <snip> 

    Then you had some poorly optimised GL code - Think about it, Quartz
    uses OpenGL to render to the screen, why would going through an extra
    layer of abstraction somehow speed up what OpenGL was doing? It may
    make your code nicer, but it won't speed it up.

    I would seriously suggest using OpenGL and if you aren't getting it
    fast then you need to go look at apples extensions doentation - you
    can get some serious speed boosts just by doing things like using the
    GL_TEXTURE_RECTANGLE_EXT extension.

    Bob
    Beelsebob Guest

  10. #10

    Default Re: Trying again: Buffer swapping and MacOS X

    Beelsebob <york.ac.uk> wrote:
     
    >
    > Then you had some poorly optimised GL code - Think about it, Quartz
    > uses OpenGL to render to the screen, why would going through an extra
    > layer of abstraction somehow speed up what OpenGL was doing? It may
    > make your code nicer, but it won't speed it up.[/ref]

    I seriously doubt that, considering Quartz wasn't built upon OpenGL at
    the time.... :)

    Also, they say Quartz still doesn't use OpenGL on my gfx card.

    I did everything correctly according to the official OpenGL
    specification, and turned off every feature I didn't need. And for that
    *specific* job it still performed way too slow...

    So what if something could have been done differently to make it faster?
    The problem is that you don't know what's happening under the surface,
    so all you can do is guess - you have no way of knowing how well the
    code is optimized, apart from trying lots of stuff and benchmarking.
    Doing the simple things by hand, I ended up making it waaaay faster that
    time, cause I knew exactly what the machine was doing.

    But this is only one specific case. In other cases, especially 3D, I've
    found OpenGL to be extremely FAST and SMOOTH (of course).

    But for this new app, OpenGL may actually be perfect after all - I'll
    try the OpenGL way first and see how it works.

    Per
    Per Guest

Similar Threads

  1. Replies: 5
    Last Post: April 12th, 02:24 AM
  2. Dir 8.5 - MacOS 9.2 projector in MacOS X Classic
    By davepla in forum Macromedia Director Basics
    Replies: 0
    Last Post: March 4th, 08:30 AM
  3. Replies: 0
    Last Post: August 23rd, 09:14 AM
  4. Free FTP clients for MacOS 7.5.5 .. MacOS 9 ?
    By Rolf Hemmerling in forum Mac Networking
    Replies: 3
    Last Post: August 12th, 01:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139