2

I have an iPhone project written with a bunch of OpenGLES, I want to now port the application to Mac / Cocoa. Can I use OpenGLES on Mac, or do I have to do a bunch of #if statements?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Stuart
  • 81
  • 2
  • 7

3 Answers3

4

As far as I can tell, ES is simply a reduced version of the desktop version—any valid ES code is valid standard GL code (perhaps with a few tweaks). Of course, on the desktop you get other functions/features too, such as rendering shapes other than triangles.

List of alternatives for functions missing in OpenGLES

Community
  • 1
  • 1
FeifanZ
  • 16,250
  • 7
  • 45
  • 84
  • 2
    I can think of only one potential difference — the MBX in the iPhones prior to the 3GS can do only one divide per pixel when technically if you load a transform with perspective onto the texture stack you need two to be visually correct. Projective texture mapping is the only significant time it comes up, with the iPhone arriving at the wrong result, giving something a bit like PS1 texture warping. Building that for the Mac would produce a program that worked but had different (and more accurate) visuals. – Tommy Mar 07 '11 at 23:35
  • The answer is Yes, with some #ifdefs. My engine uses GLES 2.0 and OGL 3+, some of the differences I've encountered are with integer vertex attributes -- these are simplified in GLES -- lack of geometry shaders, lack of Quad Lists, lack of ability to read back textures, and some texture formats. – nullspace Jan 27 '12 at 11:30
1

I've got a shared OpenGL codebase that is working across iOS and Windows. There are little sections, nothing big, like this:

// Page flip
#ifdef WIN32
    glFlush();
#else
    const GLenum discards[] = {GL_COLOR_ATTACHMENT0};
    glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards);   

    [context presentRenderbuffer:GL_RENDERBUFFER];
#endif

Other than GL startup (not using framework for that), OS user input event handlers, and shaders, the engine works identically on both platforms. I also used ifdefs in the header files to keep Objective C from "infecting" the rest of the codebase, so pure C++ files won't see class members with types such as "id" or "EAGLContext".

pTymN
  • 53
  • 4
1

OpenGL ES is a subset of OpenGL -- any OpenGL ES application should work on OpenGL ( but an OpenGL application may not work on OpenGL ES )

Dre
  • 4,298
  • 30
  • 39
  • Thanks, but the headers / includes are different, so I need #if statements for those. Plus I don't think EAGLContext exists in OpenGL? – Stuart Mar 07 '11 at 23:32
  • 1
    You may have to #if around a few calls and includes ( or refactor so all your general GL(ES) code is separate from the iOS and Mac specific code ), but in general your OpenGL ES calls should work. – Dre Mar 07 '11 at 23:37