pybullet: added EGL render device and window_backend option.

EGL review.
EGL dynamic loading, windowType to int
moved to glad2
Require GL 3.3 as GLInstancingRenderer.cpp uses glVertexAttribDivisor
glad2 update with dynamic X11 added
removed old file
build fix
fix mac/win
EGL w/o c++11, off by default
fix premake
fixup: premake fix 2
This commit is contained in:
a
2018-03-05 23:05:22 +01:00
committed by Max Argus
parent 4d00beefbb
commit 3d499c8a7a
27 changed files with 10371 additions and 9490 deletions

View File

@@ -23,7 +23,7 @@ LIST(REMOVE_ITEM OpenGLWindowCommon_CPP MacOpenGLWindow.cpp )
#MESSAGE (${OpenGLWindowCommon_CPP})
IF (WIN32)
SET(OpenGLWindow_SRCS ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/glad.c ${OpenGLWindowWin32_CPP} ${OpenGLWindowCommon_CPP})
SET(OpenGLWindow_SRCS ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/gl.c ${OpenGLWindowWin32_CPP} ${OpenGLWindowCommon_CPP})
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad
)
@@ -31,7 +31,7 @@ IF (WIN32)
ENDIF(WIN32)
IF (APPLE)
SET(OpenGLWindow_SRCS ${OpenGLWindowMac_CPP} ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/glad.c ${OpenGLWindowMacObjC_CPP} ${OpenGLWindowCommon_CPP} )
SET(OpenGLWindow_SRCS ${OpenGLWindowMac_CPP} ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/gl.c ${OpenGLWindowMacObjC_CPP} ${OpenGLWindowCommon_CPP} )
ENDIF(APPLE)
#no Linux detection?
@@ -44,7 +44,7 @@ IF(NOT WIN32 AND NOT APPLE)
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
ADD_DEFINITIONS("-DDYNAMIC_LOAD_X11_FUNCTIONS=1")
SET(OpenGLWindow_SRCS ${OpenGLWindowLinux_CPP} ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/glad_glx.c ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/glad.c ${OpenGLWindowCommon_CPP} )
SET(OpenGLWindow_SRCS ${OpenGLWindowLinux_CPP} ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/glx.c ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/gl.c ${OpenGLWindowCommon_CPP} )
ENDIF()

View File

@@ -36,11 +36,8 @@
#include <string.h>
#include <unistd.h>
#include "OpenGLInclude.h"
#include "third_party/GL/gl/include/EGL/egl.h"
#include "third_party/GL/gl/include/EGL/eglext.h"
#include "third_party/GL/gl/include/GL/gl.h"
#include <glad/gl.h>
#include <glad/egl.h>
#include "EGLOpenGLWindow.h"
@@ -49,6 +46,7 @@ struct EGLInternalData2 {
int m_windowWidth;
int m_windowHeight;
int m_renderDevice;
b3KeyboardCallback m_keyboardCallback;
b3WheelCallback m_wheelCallback;
@@ -82,6 +80,8 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
m_data->m_windowWidth = ci.m_width;
m_data->m_windowHeight = ci.m_height;
m_data->m_renderDevice = ci.m_renderDevice;
EGLint egl_config_attribs[] = {EGL_RED_SIZE,
8,
EGL_GREEN_SIZE,
@@ -101,16 +101,14 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
EGL_NONE,
};
// Initialize EGL display
PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT =
(PFNEGLQUERYDEVICESEXTPROC)eglGetProcAddress("eglQueryDevicesEXT");
if (eglQueryDevicesEXT == nullptr) m_data->egl_display = EGL_NO_DISPLAY;
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT =
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress(
"eglGetPlatformDisplayEXT");
if (eglGetPlatformDisplayEXT == nullptr) m_data->egl_display = EGL_NO_DISPLAY;
// Load EGL functions
int egl_version = gladLoadEGLInternalLoader(NULL);
if(!egl_version) {
fprintf(stderr, "failed to EGL with glad.\n");
exit(EXIT_FAILURE);
};
// Query EGL Devices
const int max_devices = 32;
EGLDeviceEXT egl_devices[max_devices];
EGLint num_devices = 0;
@@ -120,10 +118,31 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
printf("eglQueryDevicesEXT Failed.\n");
m_data->egl_display = EGL_NO_DISPLAY;
}
for (EGLint i = 0; i < num_devices; ++i) {
// Query EGL Screens
if(m_data->m_renderDevice == -1) {
// Chose default screen, by trying all
for (EGLint i = 0; i < num_devices; ++i) {
// Set display
EGLDisplay display = eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT,
egl_devices[i], NULL);
if (eglGetError() == EGL_SUCCESS && display != EGL_NO_DISPLAY) {
int major, minor;
EGLBoolean initialized = eglInitialize(display, &major, &minor);
if (eglGetError() == EGL_SUCCESS && initialized == EGL_TRUE) {
m_data->egl_display = display;
}
}
}
} else {
// Chose specific screen, by using m_renderDevice
if (m_data->m_renderDevice < 0 || m_data->m_renderDevice >= num_devices) {
fprintf(stderr, "Invalid render_device choice: %d < %d.\n", m_data->m_renderDevice, num_devices);
exit(EXIT_FAILURE);
}
// Set display
EGLDisplay display = eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT,
egl_devices[i], nullptr);
egl_devices[m_data->m_renderDevice], NULL);
if (eglGetError() == EGL_SUCCESS && display != EGL_NO_DISPLAY) {
int major, minor;
EGLBoolean initialized = eglInitialize(display, &major, &minor);
@@ -132,7 +151,21 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
}
}
}
if (!eglInitialize(m_data->egl_display, NULL, NULL)) {
fprintf(stderr, "Unable to initialize EGL\n");
exit(EXIT_FAILURE);
}
egl_version = gladLoadEGLInternalLoader(m_data->egl_display);
if (!egl_version) {
fprintf(stderr, "Unable to reload EGL.\n");
exit(EXIT_FAILURE);
}
printf("Loaded EGL %d.%d after reload.\n", egl_version / 10,
egl_version % 10);
m_data->success = eglBindAPI(EGL_OPENGL_API);
if (!m_data->success) {
// TODO: Properly handle this error (requires change to default window
@@ -140,27 +173,44 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
fprintf(stderr, "Failed to bind OpenGL API.\n");
exit(EXIT_FAILURE);
}
m_data->success =
eglChooseConfig(m_data->egl_display, egl_config_attribs,
&m_data->egl_config, 1, &m_data->num_configs);
if (!m_data->success) {
// TODO: Properly handle this error (requires change to default window
// API to change return on all window types to bool).
fprintf(stderr, "Failed to bind OpenGL API.\n");
fprintf(stderr, "Failed to choose config (eglError: %d)\n", eglGetError());
exit(EXIT_FAILURE);
}
if (m_data->num_configs != 1) {
fprintf(stderr, "Didn't get exactly one config, but %d\n", m_data->num_configs);
exit(EXIT_FAILURE);
}
m_data->egl_surface = eglCreatePbufferSurface(
m_data->egl_display, m_data->egl_config, egl_pbuffer_attribs);
if (m_data->egl_surface == EGL_NO_SURFACE) {
fprintf(stderr, "Unable to create EGL surface (eglError: %d)\n", eglGetError());
exit(EXIT_FAILURE);
}
m_data->egl_context = eglCreateContext(
m_data->egl_display, m_data->egl_config, EGL_NO_CONTEXT, nullptr);
m_data->egl_display, m_data->egl_config, EGL_NO_CONTEXT, NULL);
if (!m_data->egl_context) {
fprintf(stderr, "Unable to create EGL context (eglError: %d)\n",eglGetError());
exit(EXIT_FAILURE);
}
eglMakeCurrent(m_data->egl_display, m_data->egl_surface, m_data->egl_surface,
m_data->egl_context);
printf("Finish creating EGL OpenGL window.\n");
if (!gladLoadGLInternalLoader()) {
fprintf(stderr, "failed to GL with glad.\n");
exit(EXIT_FAILURE);
}
const GLubyte* ven = glGetString(GL_VENDOR);
printf("GL_VENDOR=%s\n", ven);

View File

@@ -3,7 +3,6 @@
#ifdef BT_USE_EGL
#define b3gDefaultOpenGLWindow EGLOpenGLWindow
#include "../CommonInterfaces/CommonWindowInterface.h"

View File

@@ -2,7 +2,7 @@
#ifdef B3_USE_GLFW
#include "GLFWOpenGLWindow.h"
#include <glad/glad.h>
#include <glad/gl.h>
#include <GLFW/glfw3.h>
#include <stdlib.h>

View File

@@ -483,8 +483,8 @@ int Mac_createWindow(struct MacOpenGLWindowInternalData* m_internalData,struct M
[m_internalData->m_myApp finishLaunching];
[pool release];
if(!gladLoadGL()) {
printf("gladLoadGL failed!\n");
if(!gladLoadGLInternalLoader()) {
printf("gladLoadGLInternalLoader failed!\n");
exit(-1);
}

View File

@@ -24,10 +24,10 @@ subject to the following restrictions:
#else
#ifdef B3_USE_GLFW
#include "glad/glad.h"
#include "glad/gl.h"
#include <GLFW/glfw3.h>
#else
#include "glad/glad.h"
#include "glad/gl.h"
#endif //B3_USE_GLFW
#endif //BT_NO_GLAD

View File

@@ -23,10 +23,10 @@ subject to the following restrictions:
#include "third_party/GL/gl/include/GL/gl.h"
#else
#ifdef B3_USE_GLFW
#include <glad/glad.h>
#include <glad/gl.h>
#include <GLFW/glfw3.h>
#else
#include "glad/glad.h"
#include "glad/gl.h"
#endif //B3_USE_GLFW
#endif //BT_NO_GLAD
#endif //__OPENGL_INCLUDE_H

View File

@@ -28,10 +28,10 @@
#include "Win32OpenGLWindow.h"
#else
//let's cross the fingers it is Linux/X11
#include "X11OpenGLWindow.h"
#ifdef BT_USE_EGL
#include "EGLOpenGLWindow.h"
#else
#include "X11OpenGLWindow.h"
#endif //BT_USE_EGL
#endif //_WIN32
#endif//__APPLE__

View File

@@ -17,10 +17,11 @@
#include "Win32OpenGLWindow.h"
#else
//let's cross the fingers it is Linux/X11
#include "X11OpenGLWindow.h"
#define BT_USE_X11 // for runtime backend selection, move to build?
#ifdef BT_USE_EGL
#include "EGLOpenGLWindow.h"
#else
#include "X11OpenGLWindow.h"
#endif //BT_USE_EGL
#endif //_WIN32
#endif//__APPLE__
@@ -295,7 +296,7 @@ static void printGLString(const char *name, GLenum s) {
bool sOpenGLVerbose = true;
SimpleOpenGL3App::SimpleOpenGL3App(const char* title, int width, int height, bool allowRetina, int maxNumObjectCapacity, int maxShapeCapacityInBytes)
SimpleOpenGL3App::SimpleOpenGL3App(const char* title, int width, int height, bool allowRetina, int maxNumObjectCapacity, int maxShapeCapacityInBytes, int windowType, int renderDevice)
{
gApp = this;
@@ -306,7 +307,28 @@ SimpleOpenGL3App::SimpleOpenGL3App(const char* title, int width, int height, boo
m_data->m_userPointer = 0;
m_data->m_upAxis = 1;
m_window = new b3gDefaultOpenGLWindow();
if( windowType == 0) {
m_window = new b3gDefaultOpenGLWindow();
} else if (windowType == 1) {
#ifdef BT_USE_X11
m_window = new X11OpenGLWindow();
#else
b3Warning("X11 requires Linux. Loading default window instead. \n");
m_window = new b3gDefaultOpenGLWindow();
#endif
} else if ( windowType == 2 ) {
#ifdef BT_USE_EGL
m_window = new EGLOpenGLWindow();
#else
b3Warning("EGL window requires compilation with BT_USE_EGL.\n");
b3Warning("Loading default window instead. \n");
m_window = new b3gDefaultOpenGLWindow();
#endif
} else {
b3Warning("Unknown window type %d must be (0=default, 1=X11, 2=EGL).\n", windowType);
b3Warning("Loading default window instead. \n");
m_window = new b3gDefaultOpenGLWindow();
}
m_window->setAllowRetina(allowRetina);
@@ -314,6 +336,7 @@ SimpleOpenGL3App::SimpleOpenGL3App(const char* title, int width, int height, boo
ci.m_title = title;
ci.m_width = width;
ci.m_height = height;
ci.m_renderDevice = renderDevice;
m_window->createWindow(ci);
m_window->setWindowTitle(title);

View File

@@ -16,7 +16,7 @@ struct SimpleOpenGL3App : public CommonGraphicsApp
class GLInstancingRenderer* m_instancingRenderer;
virtual void setBackgroundColor(float red, float green, float blue);
SimpleOpenGL3App(const char* title, int width,int height, bool allowRetina=true, int maxNumObjectCapacity = 128 * 1024, int maxShapeCapacityInBytes = 128 * 1024 * 1024);
SimpleOpenGL3App(const char* title, int width,int height, bool allowRetina=true, int maxNumObjectCapacity = 128 * 1024, int maxShapeCapacityInBytes = 128 * 1024 * 1024, int windowType=0, int renderDevice=-1);
virtual ~SimpleOpenGL3App();

View File

@@ -84,8 +84,8 @@ void Win32OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
//VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
enableOpenGL();
if(!gladLoadGL()) {
printf("gladLoadGL failed!\n");
if(!gladLoadGLInternalLoader()) {
printf("gladLoadGLInternalLoader failed!\n");
exit(-1);
}
@@ -195,4 +195,4 @@ int Win32OpenGLWindow::getHeight() const
#endif
#endif //B3_USE_GLFW
#endif //B3_USE_GLFW

View File

@@ -6,9 +6,14 @@
#include<stdio.h>
#include<stdlib.h>
#ifdef GLEW_STATIC
#include "glad/gl.h"
#else
#include <GL/glew.h>
#endif//GLEW_STATIC
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
#include "glad/glad_glx.h"
#include "glad/glx.h"
#else
#include <GL/glx.h>
#endif // GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
@@ -369,7 +374,7 @@ void X11OpenGLWindow::enableOpenGL()
GLXContext ctx = 0;
// Install an X error handler so the application won't exit if GL 3.0
// Install an X error handler so the application won't exit if GL 3.3
// context allocation fails.
//
// Note this error handler is global. All display connections in all threads
@@ -389,12 +394,12 @@ void X11OpenGLWindow::enableOpenGL()
ctx = glXCreateNewContext( m_data->m_dpy, m_data->m_bestFbc, GLX_RGBA_TYPE, 0, True );
}
// If it does, try to get a GL 3.0 context!
// If it does, try to get a GL 3.3 context!
else
{
int context_attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB ,3,
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,None
};
@@ -415,10 +420,10 @@ void X11OpenGLWindow::enableOpenGL()
// Sync to ensure any errors generated are processed.
MyXSync( m_data->m_dpy, False );
if ( !ctxErrorOccurred && ctx )
printf( "Created GL 3.0 context\n" );
printf( "Created GL 3.3 context\n" );
else
{
// Couldn't create GL 3.0 context. Fall back to old-style 2.x context.
// Couldn't create GL 3.3 context. Fall back to old-style 2.x context.
// When a context version below 3.0 is requested, implementations will
// return the newest context version compatible with OpenGL versions less
// than version 3.0.
@@ -429,7 +434,7 @@ void X11OpenGLWindow::enableOpenGL()
ctxErrorOccurred = false;
printf( "Failed to create GL 3.0 context"
printf( "Failed to create GL 3.3 context"
" ... using old-style GLX context\n" );
ctx = glXCreateContextAttribsARB( m_data->m_dpy, m_data->m_bestFbc, 0,
True, context_attribs );
@@ -468,7 +473,7 @@ void X11OpenGLWindow::enableOpenGL()
glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc);
}
if(!gladLoadGL()) {
if(!gladLoadGLInternalLoader()) {
printf("gladLoadGL failed!\n");
exit(-1);
}
@@ -519,12 +524,13 @@ void X11OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
#ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
int res=gladLoadGLX(m_data->m_dpy,DefaultScreen(m_data->m_dpy));
if (!res)
{
printf("Error in gladLoadGLX\n");
exit(0);
}
int res=gladLoadGLXInternalLoader(m_data->m_dpy,DefaultScreen(m_data->m_dpy));
if (!res)
{
printf("Error in gladLoadGLX\n");
exit(0);
}
#endif