Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 20, 2011, 04:55 AM   #1
Ian Moody
macrumors newbie
 
Join Date: Sep 2009
Fastest, simplest way to blit a block of memory to the screen

Hi,

I'm in the process of writing a software 3d engine (just for fun, keeps my mind busy) and I would be very interested to know what the fastest way of blitting my rendered output to the screen would be (I'm of course aware that you can't ACTUALLY just blit something into screen memory directly) .

I'm currently using a few basic OpenGL / GLUT calls to create a large texture from my rendered bitmap data and then render it into a window (yes, I know, using OpenGL to render bitmap to the screen is a bit silly), updating the texture every frame.

My application is completely C based, although I would be happy to have one source file in (say) Objective-C if that file could handle the blitting side of things for me.

So what I need is the simplest way to:

*) Create a plain window at a specific (content) size (w,h)
*) Blit a block of memory to that window
*) Repeat.

The only user interaction I need is to handle the Quit command.

Any pointers would be really appreciated

Update:- Reading though some other forum posts it seems like OpenGL / Quartz is the way to do it, but with OpenGL insisting on power of two textures it seems wasteful to have to make and update a 1042 x 1024 texture to update a 600x600 window for example.

Ian Moody

Last edited by Ian Moody; May 20, 2011 at 05:10 AM. Reason: Read some other posts in the forums :)
Ian Moody is offline   0 Reply With Quote
Old May 20, 2011, 09:53 AM   #2
firewood
macrumors 603
 
Join Date: Jul 2003
Location: Silicon Valley
One fast way is to assign your arbitrary sized block of memory to a CGBitmapContext, convert that bitmap context to an image, assign that image to the contents of a visible CALayer, then doing a CATransaction commit when the entire frame is ready. Helps to double (or triple) buffer all the bitmaps. But, under the hood, all this might get converted into Open GL texture loads to the GPU anyway; so if you've done that, you're done. All iOS device display memory appears to be on the other side of the GPU, so there's absolutely no way to write to iOS display without going through a GPU texture load or triangle fill.

One possible optimization for non-power-of-2 blits is to put multiple odd-sized bitmaps inside one larger 2^N texture map atlas.

Last edited by firewood; May 20, 2011 at 11:37 AM.
firewood is offline   0 Reply With Quote
Old May 20, 2011, 02:06 PM   #3
SidBala
macrumors 6502a
 
Join Date: Jun 2010
Quote:
Originally Posted by Ian Moody View Post

Update:- Reading though some other forum posts it seems like OpenGL / Quartz is the way to do it, but with OpenGL insisting on power of two textures it seems wasteful to have to make and update a 1042 x 1024 texture to update a 600x600 window for example.
Using a OpenGL window to render a bitmap is not at all silly. I do it all the time. You can use the GPU to do your interpolation and resizing. It can even make for a very good zoom window, when you want to magnify parts of the image you are displaying.

Also, there is an extension that allows non-power of two textures. There is also a texture type - texture_rectangle that allows non-normalized texture coordinates. But I would recommend not using these.

If you really wanted to just blit to the screen, you can use glDrawPixels. This is a very simply function that just writes directly to the framebuffer.

glDrawPixels is probably the simplest way to achieve what you want, given that you already have an opengl window running.
SidBala is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Simplest way to block specific websites (& probs with multiple accounts)? steveLONDON OS X 8 Jan 6, 2014 08:48 AM
(Some results) What's the fastest stable memory for an early 2011 13" i7 MBPro? adb1973 MacBook Pro 20 Jun 2, 2013 04:30 PM
iPhone doesn't block screen while charging iphoneipoduser iOS 6 0 Sep 22, 2012 04:31 PM

Forum Jump

All times are GMT -5. The time now is 06:40 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC