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)
ENDIF (OPENGL_FOUND)
# ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
#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)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
@@ -207,6 +198,7 @@ IF(BUILD_BULLET3)
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")
#unset(BUILD_OPENGL3_DEMOS CACHE)
OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build the OpenGL3+ demos" OFF)
ELSE()
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)
SUBDIRS(Demos3)
ENDIF()
ELSE()
ADD_DEFINITIONS(-DNO_OPENGL3)
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)
IF(BUILD_EXTRAS)
SUBDIRS(Extras)

View File

@@ -29,6 +29,10 @@
configuration {"Windows"}
links {"opengl32","glu32"}
configuration {"MacOSX"}
if (not findOpenGL3()) then
defines {"NO_OPENGL3"}
end
links { "OpenGL.framework"}
configuration {"not Windows", "not MacOSX"}
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"
#ifdef B3_USE_CLEW
#ifndef NO_OPENGL3
#include "../OpenCL/broadphase/PairBench.h"
#include "../OpenCL/rigidbody/GpuConvexScene.h"
#endif
#endif //B3_USE_CLEW
@@ -193,6 +194,7 @@ static ExampleEntry gDefaultExamples[]=
};
#ifdef B3_USE_CLEW
#ifndef NO_OPENGL3
static ExampleEntry gOpenCLExamples[]=
{
ExampleEntry(0,"OpenCL (experimental)"),
@@ -201,6 +203,7 @@ static ExampleEntry gOpenCLExamples[]=
ExampleEntry(1,"Pair Bench", "Benchmark of overlapping pair search using OpenCL.", PairBenchOpenCLCreateFunc),
};
#endif
#endif //
static btAlignedObjectArray<ExampleEntry> gAdditionalRegisteredExamples;
@@ -223,11 +226,13 @@ ExampleEntries::~ExampleEntries()
void ExampleEntries::initOpenCLExampleEntries()
{
#ifdef B3_USE_CLEW
#ifndef NO_OPENGL3
int numDefaultEntries = sizeof(gOpenCLExamples)/sizeof(ExampleEntry);
for (int i=0;i<numDefaultEntries;i++)
{
m_data->m_allExamples.push_back(gOpenCLExamples[i]);
}
#endif
#endif //B3_USE_CLEW
}

View File

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

View File

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

View File

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

View File

@@ -1,3 +1,4 @@
#ifndef NO_OPENGL3
#include "GLPrimitiveRenderer.h"
#include "GLPrimInternalData.h"
@@ -320,3 +321,4 @@ void GLPrimitiveRenderer::setScreenSize(int width, int 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/
@@ -132,4 +133,5 @@ GLRenderToTexture::~GLRenderToTexture()
glDeleteFramebuffers(1, &m_framebufferName);
}
}
#endif

View File

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

View File

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

View File

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

View File

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

View File

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