allow to compile and run the ExampleBrowser on older Mac OSX versions (without OpenGL3)

using the 'NO_OPENGL3' preprocessor definition
both premake/cmake has support for this now
needs some testing
This commit is contained in:
Erwin Coumans
2015-05-06 10:35:14 -07:00
parent c2006f31e4
commit 0da584a42d
14 changed files with 82 additions and 36 deletions

View File

@@ -180,20 +180,11 @@ ELSE (OPENGL_FOUND)
SET(OPENGL_glu_LIBRARY glu32) SET(OPENGL_glu_LIBRARY glu32)
ENDIF (OPENGL_FOUND) ENDIF (OPENGL_FOUND)
# ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
#FIND_PACKAGE(GLU) #FIND_PACKAGE(GLU)
OPTION(BUILD_BULLET2_DEMOS "Set when you want to build the Bullet 2 demos" ON)
IF(BUILD_BULLET2_DEMOS AND BUILD_OPENGL3_DEMOS)
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/examples AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/examples)
SUBDIRS(examples)
ENDIF()
ENDIF(BUILD_BULLET2_DEMOS)
IF (APPLE) IF (APPLE)
FIND_LIBRARY(COCOA_LIBRARY Cocoa) FIND_LIBRARY(COCOA_LIBRARY Cocoa)
@@ -207,6 +198,7 @@ IF(BUILD_BULLET3)
IF(_CURRENT_OSX_VERSION VERSION_LESS 10.9) IF(_CURRENT_OSX_VERSION VERSION_LESS 10.9)
MESSAGE("Mac OSX below 10.9 has no OpenGL 3 support so please disable the BUILD_OPENGL3_DEMOS option") MESSAGE("Mac OSX below 10.9 has no OpenGL 3 support so please disable the BUILD_OPENGL3_DEMOS option")
#unset(BUILD_OPENGL3_DEMOS CACHE) #unset(BUILD_OPENGL3_DEMOS CACHE)
OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build the OpenGL3+ demos" OFF) OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build the OpenGL3+ demos" OFF)
ELSE() ELSE()
OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build the OpenGL3+ demos" ON) OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build the OpenGL3+ demos" ON)
@@ -222,8 +214,20 @@ IF(BUILD_OPENGL3_DEMOS)
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos3) IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos3)
SUBDIRS(Demos3) SUBDIRS(Demos3)
ENDIF() ENDIF()
ELSE()
ADD_DEFINITIONS(-DNO_OPENGL3)
ENDIF(BUILD_OPENGL3_DEMOS) ENDIF(BUILD_OPENGL3_DEMOS)
OPTION(BUILD_BULLET2_DEMOS "Set when you want to build the Bullet 2 demos" ON)
IF(BUILD_BULLET2_DEMOS)
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/examples AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/examples)
SUBDIRS(examples)
ENDIF()
ENDIF(BUILD_BULLET2_DEMOS)
OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON) OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON)
IF(BUILD_EXTRAS) IF(BUILD_EXTRAS)
SUBDIRS(Extras) SUBDIRS(Extras)

View File

@@ -29,6 +29,10 @@
configuration {"Windows"} configuration {"Windows"}
links {"opengl32","glu32"} links {"opengl32","glu32"}
configuration {"MacOSX"} configuration {"MacOSX"}
if (not findOpenGL3()) then
defines {"NO_OPENGL3"}
end
links { "OpenGL.framework"} links { "OpenGL.framework"}
configuration {"not Windows", "not MacOSX"} configuration {"not Windows", "not MacOSX"}
if os.is("Linux") then if os.is("Linux") then

BIN
build3/premake4_osx32 Executable file

Binary file not shown.

View File

@@ -33,9 +33,10 @@
#include "../RollingFrictionDemo/RollingFrictionDemo.h" #include "../RollingFrictionDemo/RollingFrictionDemo.h"
#ifdef B3_USE_CLEW #ifdef B3_USE_CLEW
#ifndef NO_OPENGL3
#include "../OpenCL/broadphase/PairBench.h" #include "../OpenCL/broadphase/PairBench.h"
#include "../OpenCL/rigidbody/GpuConvexScene.h" #include "../OpenCL/rigidbody/GpuConvexScene.h"
#endif
#endif //B3_USE_CLEW #endif //B3_USE_CLEW
@@ -193,6 +194,7 @@ static ExampleEntry gDefaultExamples[]=
}; };
#ifdef B3_USE_CLEW #ifdef B3_USE_CLEW
#ifndef NO_OPENGL3
static ExampleEntry gOpenCLExamples[]= static ExampleEntry gOpenCLExamples[]=
{ {
ExampleEntry(0,"OpenCL (experimental)"), ExampleEntry(0,"OpenCL (experimental)"),
@@ -201,6 +203,7 @@ static ExampleEntry gOpenCLExamples[]=
ExampleEntry(1,"Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc), ExampleEntry(1,"Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc),
}; };
#endif
#endif // #endif //
static btAlignedObjectArray<ExampleEntry> gAdditionalRegisteredExamples; static btAlignedObjectArray<ExampleEntry> gAdditionalRegisteredExamples;
@@ -223,11 +226,13 @@ ExampleEntries::~ExampleEntries()
void ExampleEntries::initOpenCLExampleEntries() void ExampleEntries::initOpenCLExampleEntries()
{ {
#ifdef B3_USE_CLEW #ifdef B3_USE_CLEW
#ifndef NO_OPENGL3
int numDefaultEntries = sizeof(gOpenCLExamples)/sizeof(ExampleEntry); int numDefaultEntries = sizeof(gOpenCLExamples)/sizeof(ExampleEntry);
for (int i=0;i<numDefaultEntries;i++) for (int i=0;i<numDefaultEntries;i++)
{ {
m_data->m_allExamples.push_back(gOpenCLExamples[i]); m_data->m_allExamples.push_back(gOpenCLExamples[i]);
} }
#endif
#endif //B3_USE_CLEW #endif //B3_USE_CLEW
} }

View File

@@ -2,7 +2,9 @@
#include "LinearMath/btQuickprof.h" #include "LinearMath/btQuickprof.h"
#include "../OpenGLWindow/OpenGLInclude.h" #include "../OpenGLWindow/OpenGLInclude.h"
#include "../OpenGLWindow/SimpleOpenGL2App.h" #include "../OpenGLWindow/SimpleOpenGL2App.h"
#ifndef NO_OPENGL3
#include "../OpenGLWindow/SimpleOpenGL3App.h" #include "../OpenGLWindow/SimpleOpenGL3App.h"
#endif
#include "../CommonInterfaces/CommonRenderInterface.h" #include "../CommonInterfaces/CommonRenderInterface.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include "../OpenGLWindow/MacOpenGLWindow.h" #include "../OpenGLWindow/MacOpenGLWindow.h"
@@ -60,7 +62,10 @@ static b3AlignedObjectArray<const char*> allNames;
static class ExampleEntries* gAllExamples=0; static class ExampleEntries* gAllExamples=0;
bool sUseOpenGL2 = false; bool sUseOpenGL2 = false;
bool drawGUI=true; bool drawGUI=true;
#ifndef USE_OPENGL3
extern bool useShadowMap; extern bool useShadowMap;
#endif
static bool visualWireframe=false; static bool visualWireframe=false;
static bool renderVisualGeometry=true; static bool renderVisualGeometry=true;
static bool renderGrid = true; static bool renderGrid = true;
@@ -150,12 +155,12 @@ void MyKeyboardCallback(int key, int state)
{ {
pauseSimulation = !pauseSimulation; pauseSimulation = !pauseSimulation;
} }
#ifndef NO_OPENGL3
if (key=='s' && state) if (key=='s' && state)
{ {
useShadowMap=!useShadowMap; useShadowMap=!useShadowMap;
} }
#endif
if (key==B3G_ESCAPE && s_window) if (key==B3G_ESCAPE && s_window)
{ {
s_window->setRequestExit(); s_window->setRequestExit();
@@ -598,10 +603,12 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
int width = 1024; int width = 1024;
int height=768; int height=768;
#ifndef NO_OPENGL3
SimpleOpenGL3App* simpleApp=0; SimpleOpenGL3App* simpleApp=0;
sUseOpenGL2 =args.CheckCmdLineFlag("opengl2"); sUseOpenGL2 =args.CheckCmdLineFlag("opengl2");
#else
sUseOpenGL2 = true;
#endif
const char* appTitle = "Bullet Physics ExampleBrowser"; const char* appTitle = "Bullet Physics ExampleBrowser";
#if defined (_DEBUG) || defined (DEBUG) #if defined (_DEBUG) || defined (DEBUG)
const char* optMode = "Debug build (slow)"; const char* optMode = "Debug build (slow)";
@@ -615,19 +622,22 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
sprintf(title,"%s using limited OpenGL2 fallback. %s", appTitle,optMode); sprintf(title,"%s using limited OpenGL2 fallback. %s", appTitle,optMode);
s_app = new SimpleOpenGL2App(title,width,height); s_app = new SimpleOpenGL2App(title,width,height);
s_app->m_renderer = new SimpleOpenGL2Renderer(width,height); s_app->m_renderer = new SimpleOpenGL2Renderer(width,height);
} else }
#ifndef NO_OPENGL3
else
{ {
char title[1024]; char title[1024];
sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode); sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode);
simpleApp = new SimpleOpenGL3App(title,width,height); simpleApp = new SimpleOpenGL3App(title,width,height);
s_app = simpleApp; s_app = simpleApp;
} }
#endif
char* gVideoFileName = 0; char* gVideoFileName = 0;
args.GetCmdLineArgument("mp4",gVideoFileName); args.GetCmdLineArgument("mp4",gVideoFileName);
#ifndef NO_OPENGL3
if (gVideoFileName) if (gVideoFileName)
simpleApp->dumpFramesToVideo(gVideoFileName); simpleApp->dumpFramesToVideo(gVideoFileName);
#endif
s_instancingRenderer = s_app->m_renderer; s_instancingRenderer = s_app->m_renderer;
s_window = s_app->m_window; s_window = s_app->m_window;
@@ -658,11 +668,14 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
if (sUseOpenGL2 ) if (sUseOpenGL2 )
{ {
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(); gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
} else }
#ifndef NO_OPENGL3
else
{ {
sth_stash* fontstash=simpleApp->getFontStash(); sth_stash* fontstash=simpleApp->getFontStash();
gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader); gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader);
} }
#endif
// //
gui->init(width,height,gwenRenderer,s_window->getRetinaScale()); gui->init(width,height,gwenRenderer,s_window->getRetinaScale());

View File

@@ -93,7 +93,7 @@
} }
if (hasCL) then if (hasCL and findOpenGL3()) then
files { files {
"../OpenCL/broadphase/*", "../OpenCL/broadphase/*",
"../OpenCL/CommonOpenCL/*", "../OpenCL/CommonOpenCL/*",

View File

@@ -1,3 +1,4 @@
#ifndef NO_OPENGL3
/* /*
Copyright (c) 2012 Advanced Micro Devices, Inc. Copyright (c) 2012 Advanced Micro Devices, Inc.
@@ -1641,3 +1642,4 @@ int GLInstancingRenderer::getInstanceCapacity() const
{ {
return m_data->m_maxNumObjectCapacity; return m_data->m_maxNumObjectCapacity;
} }
#endif //NO_OPENGL3

View File

@@ -1,3 +1,4 @@
#ifndef NO_OPENGL3
#include "GLPrimitiveRenderer.h" #include "GLPrimitiveRenderer.h"
#include "GLPrimInternalData.h" #include "GLPrimInternalData.h"
@@ -320,3 +321,4 @@ void GLPrimitiveRenderer::setScreenSize(int width, int height)
m_screenHeight = height; m_screenHeight = height;
} }
#endif

View File

@@ -1,3 +1,4 @@
#ifndef NO_OPENGL3
///See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/ ///See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/
@@ -132,4 +133,5 @@ GLRenderToTexture::~GLRenderToTexture()
glDeleteFramebuffers(1, &m_framebufferName); glDeleteFramebuffers(1, &m_framebufferName);
} }
} }
#endif

View File

@@ -2,8 +2,8 @@
#define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED #define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include <OpenGL/gl3.h> #include "OpenGLInclude.h"
#include <OpenGL/gl3ext.h>
#include <stdlib.h> #include <stdlib.h>
@@ -107,16 +107,16 @@ float loop;
{ {
(*m_resizeCallback)(width,height); (*m_resizeCallback)(width,height);
} }
#ifndef NO_OPENGL3
NSRect backingBounds = [self convertRectToBacking:[self bounds]]; NSRect backingBounds = [self convertRectToBacking:[self bounds]];
GLsizei backingPixelWidth = (GLsizei)(backingBounds.size.width), GLsizei backingPixelWidth = (GLsizei)(backingBounds.size.width),
backingPixelHeight = (GLsizei)(backingBounds.size.height); backingPixelHeight = (GLsizei)(backingBounds.size.height);
// Set viewport // Set viewport
glViewport(0, 0, backingPixelWidth, backingPixelHeight); glViewport(0, 0, backingPixelWidth, backingPixelHeight);
#else
// glViewport(0,0,(GLsizei)width,(GLsizei)height); glViewport(0,0,(GLsizei)width,(GLsizei)height);
#endif
} }
[m_context setView: self]; [m_context setView: self];
@@ -140,7 +140,7 @@ float loop;
#ifndef NO_OPENGL3
if (openglVersion==3) if (openglVersion==3)
{ {
NSOpenGLPixelFormatAttribute attrs[] = NSOpenGLPixelFormatAttribute attrs[] =
@@ -156,6 +156,7 @@ float loop;
// Init GL context // Init GL context
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*)attrs]; fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*)attrs];
} else } else
#endif
{ {
NSOpenGLPixelFormatAttribute attrs[] = NSOpenGLPixelFormatAttribute attrs[] =
{ {
@@ -437,8 +438,11 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
TransformProcessType(&psn, kProcessTransformToForegroundApplication); TransformProcessType(&psn, kProcessTransformToForegroundApplication);
SetFrontProcess(&psn); SetFrontProcess(&psn);
*/ */
#ifndef NO_OPENGL3
m_retinaScaleFactor = [m_internalData->m_myview convertSizeToBacking:sz].width; m_retinaScaleFactor = [m_internalData->m_myview convertSizeToBacking:sz].width;
#else
m_retinaScaleFactor=1.f;
#endif
[m_internalData->m_myApp finishLaunching]; [m_internalData->m_myApp finishLaunching];
[pool release]; [pool release];

View File

@@ -24,7 +24,7 @@ subject to the following restrictions:
//#include <OpenGL/gl.h> //#include <OpenGL/gl.h>
//#include <OpenGL/glu.h> //#include <OpenGL/glu.h>
//#import <Cocoa/Cocoa.h> //#import <Cocoa/Cocoa.h>
#ifdef USE_OPENGL2 #if defined (USE_OPENGL2) || defined (NO_OPENGL3)
#include <OpenGL/gl.h> #include <OpenGL/gl.h>
#else #else
#include <OpenGL/gl3.h> #include <OpenGL/gl3.h>

View File

@@ -1,3 +1,4 @@
#ifndef NO_OPENGL3
#include "opengl_fontstashcallbacks.h" #include "opengl_fontstashcallbacks.h"
#include "../OpenGLWindow/GLPrimitiveRenderer.h" #include "../OpenGLWindow/GLPrimitiveRenderer.h"
#include "../OpenGLWindow/GLPrimInternalData.h" #include "../OpenGLWindow/GLPrimInternalData.h"
@@ -250,3 +251,5 @@ void dumpTextureToPng(int textureWidth, int textureHeight, const char* fileName)
free(pixels); free(pixels);
} }
#endif

View File

@@ -301,13 +301,11 @@ Hinge2Vehicle::~Hinge2Vehicle()
} }
extern float shadowMapWorldSize;
void Hinge2Vehicle::initPhysics() void Hinge2Vehicle::initPhysics()
{ {
m_guiHelper->setUpAxis(1); m_guiHelper->setUpAxis(1);
shadowMapWorldSize = 10;
btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50)); btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
m_collisionShapes.push_back(groundShape); m_collisionShapes.push_back(groundShape);

View File

@@ -2,6 +2,7 @@
#include "Gwen/Gwen.h" #include "Gwen/Gwen.h"
#include "Gwen/Skins/Simple.h" #include "Gwen/Skins/Simple.h"
#include "../OpenGLWindow/OpenGLInclude.h"
#include "UnitTest.h" #include "UnitTest.h"
@@ -22,9 +23,10 @@ extern unsigned char OpenSansData[];
#endif//__APPLE__ #endif//__APPLE__
#include "OpenGLWindow/opengl_fontstashcallbacks.h" #include "OpenGLWindow/opengl_fontstashcallbacks.h"
#ifndef NO_OPENGL3
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h" #include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
#include "OpenGLWindow/GLPrimitiveRenderer.h" #include "OpenGLWindow/GLPrimitiveRenderer.h"
#endif
#include <assert.h> #include <assert.h>
Gwen::Controls::Canvas* pCanvas = NULL; Gwen::Controls::Canvas* pCanvas = NULL;
@@ -79,10 +81,12 @@ static void MyResizeCallback( float width, float height)
sWidth = width; sWidth = width;
sHeight = height; sHeight = height;
// printf("resize(%d,%d)\n",sWidth,sHeight); // printf("resize(%d,%d)\n",sWidth,sHeight);
#ifndef NO_OPENGL3
if (primRenderer) if (primRenderer)
{ {
primRenderer->setScreenSize(width,height); primRenderer->setScreenSize(width,height);
} }
#endif
if (gwenRenderer) if (gwenRenderer)
{ {
gwenRenderer->Resize(width,height); gwenRenderer->Resize(width,height);
@@ -96,7 +100,7 @@ static void MyResizeCallback( float width, float height)
int droidRegular;//, droidItalic, droidBold, droidJapanese, dejavu; int droidRegular;//, droidItalic, droidBold, droidJapanese, dejavu;
#ifndef NO_OPENGL3
sth_stash* initFont(GLPrimitiveRenderer* primRenderer) sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
{ {
GLint err; GLint err;
@@ -217,7 +221,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
return stash; return stash;
} }
#endif
void keyCallback(int key, int value) void keyCallback(int key, int value)
{ {
printf("key = %d, value = %d\n", key,value); printf("key = %d, value = %d\n", key,value);
@@ -308,7 +312,11 @@ int main()
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow(); b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
window->setKeyboardCallback(keyCallback); window->setKeyboardCallback(keyCallback);
b3gWindowConstructionInfo wci; b3gWindowConstructionInfo wci;
wci.m_openglVersion = 2; #ifndef NO_OPENGL3
wci.m_openglVersion = 3;
#else
wci.m_openglVersion = 2;
#endif
wci.m_width = sWidth; wci.m_width = sWidth;
wci.m_height = sHeight; wci.m_height = sHeight;
// wci.m_resizeCallback = MyResizeCallback; // wci.m_resizeCallback = MyResizeCallback;
@@ -333,7 +341,7 @@ int main()
sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion); sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion);
} }
window->setWindowTitle(title); window->setWindowTitle(title);
#ifndef NO_OPENGL3
if (majorGlVersion>=3 && wci.m_openglVersion>=3) if (majorGlVersion>=3 && wci.m_openglVersion>=3)
{ {
float retinaScale = 1.f; float retinaScale = 1.f;
@@ -363,6 +371,7 @@ int main()
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale); gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
} else } else
#endif
{ {
//OpenGL 2.x //OpenGL 2.x
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(); gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();