Stuart
Stuart

Reputation: 81

OpenGL code shared on iPhone and Mac

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?

Upvotes: 2

Views: 591

Answers (3)

pTymN
pTymN

Reputation: 53

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".

Upvotes: 1

Dre
Dre

Reputation: 4329

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 )

Upvotes: 1

FeifanZ
FeifanZ

Reputation: 16316

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

Upvotes: 4

Related Questions