Skip to content

Commit

Permalink
supports the Rpi 4 with EGL and GLFW. Closes #6436 (#6438)
Browse files Browse the repository at this point in the history
* supports the Rpi 4 with EGL and GLFW. Closes #6436

* better defines for rpi. changed make file to reflect.

* updated config.linuxarmv7l.raspberry2.mk to reflect changes to armv6l changes

* detect new Raspbian releases and disable legacy system in make file

* adding glfw to multistrap.conf
  • Loading branch information
ofTheo committed Nov 14, 2019
1 parent 5f191cc commit 261af06
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 43 deletions.
4 changes: 2 additions & 2 deletions libs/openFrameworks/app/ofAppBaseWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct __GLXcontextRec;
typedef __GLXcontextRec * GLXContext;
#endif

#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI)
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)
typedef unsigned long Window;
struct _XDisplay;
typedef struct _XDisplay Display;
Expand Down Expand Up @@ -77,7 +77,7 @@ class ofAppBaseWindow{

virtual void * getWindowContext(){return nullptr;};

#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI)
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)
virtual Display* getX11Display(){return nullptr;}
virtual Window getX11Window() {return 0;}
#endif
Expand Down
26 changes: 13 additions & 13 deletions libs/openFrameworks/app/ofAppEGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ EGLContext ofAppEGLWindow::getEglContext() const {
return eglContext;
}

#ifndef TARGET_RASPBERRY_PI
#ifndef TARGET_RASPBERRY_PI_LEGACY
//------------------------------------------------------------
Display* ofAppEGLWindow::getX11Display(){
return x11Display;
Expand Down Expand Up @@ -315,14 +315,14 @@ EGLint ofAppEGLWindow::getEglVersionMinor() const {

//------------------------------------------------------------
void ofAppEGLWindow::initNative() {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
initRPiNative();
#endif
}

//------------------------------------------------------------
void ofAppEGLWindow::exitNative() {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
exitRPiNative();
#endif
}
Expand All @@ -337,7 +337,7 @@ EGLNativeWindowType ofAppEGLWindow::getNativeWindow() {
if(isUsingX11) {
return (EGLNativeWindowType)x11Window;
} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
return (EGLNativeWindowType)&dispman_native_window;
#else
ofLogNotice("ofAppEGLWindow") << "getNativeWindow(): no native window type for this system, perhaps try X11?";
Expand All @@ -356,7 +356,7 @@ EGLNativeDisplayType ofAppEGLWindow::getNativeDisplay() {
if(isUsingX11) {
return (EGLNativeDisplayType)x11Display;
} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
return (EGLNativeDisplayType)NULL;
#else
ofLogNotice("ofAppEGLWindow") << "getNativeDisplay(): no native window type for this system, perhaps try X11?";
Expand Down Expand Up @@ -429,7 +429,7 @@ void ofAppEGLWindow::setup(const ofAppEGLWindowSettings & _settings) {

////////////////
// TODO remove the following ifdef once x11 is accelerated on RPI
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
if(isUsingX11) {
isUsingX11 = false;
ofLogWarning("ofAppEGLWindow") << "init(): X11 not availble on RPI yet, using a native window instead";
Expand Down Expand Up @@ -758,7 +758,7 @@ bool ofAppEGLWindow::destroyWindow() {
XDestroyWindow(x11Display,x11Window); // or XCloseWindow?
XFree(x11Screen);
} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
dispman_update = vc_dispmanx_update_start(0);
if (dispman_element != DISPMANX_NO_HANDLE) {
vc_dispmanx_element_remove(dispman_update, dispman_element);
Expand Down Expand Up @@ -942,7 +942,7 @@ void ofAppEGLWindow::setWindowRect(const ofRectangle& requestedWindowRect) {
currentWindowRect = newRect;
}
} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY

VC_RECT_T dst_rect;
dst_rect.x = (int32_t)newRect.x;
Expand Down Expand Up @@ -996,7 +996,7 @@ bool ofAppEGLWindow::createWindow(const ofRectangle& requestedWindowRect) {
if(isUsingX11) {
return createX11NativeWindow(requestedWindowRect);
} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
return createRPiNativeWindow(requestedWindowRect);
#else
ofLogError("ofAppEGLWindow") << "createEGLWindow(): no native window type for this system, perhaps try X11?";
Expand Down Expand Up @@ -1097,7 +1097,7 @@ glm::vec2 ofAppEGLWindow::getScreenSize(){
}

} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
int success = graphics_get_display_size(settings.screenNum, &screenWidth, &screenHeight);
if(success < 0) {
ofLogError("ofAppEGLWindow") << "getScreenSize(): tried to get display size but failed";
Expand Down Expand Up @@ -1165,7 +1165,7 @@ void ofAppEGLWindow::setWindowPosition(int x, int y){
nonFullscreenWindowRect = currentWindowRect;
}
} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY

// keep it in bounds
auto screenSize = getScreenSize();
Expand Down Expand Up @@ -1226,7 +1226,7 @@ void ofAppEGLWindow::setWindowShape(int w, int h){
nonFullscreenWindowRect = currentWindowRect;
}
} else {
#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
setWindowRect(ofRectangle(currentWindowRect.x,currentWindowRect.y,w,h));
nonFullscreenWindowRect = currentWindowRect;
#else
Expand Down Expand Up @@ -1836,7 +1836,7 @@ void ofAppEGLWindow::readNativeInputEvents(){
}
}

#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
//------------------------------------------------------------
void ofAppEGLWindow::initRPiNative() {
bcm_host_init();
Expand Down
10 changes: 5 additions & 5 deletions libs/openFrameworks/app/ofAppEGLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ enum ofAppEGLWindowType {
OF_APP_WINDOW_X11
};

typedef std::map<EGLint,EGLint> ofEGLAttributeList;
typedef std::map<EGLint,EGLint>::iterator ofEGLAttributeListIterator;

typedef struct _XIM * XIM;
typedef struct _XIC * XIC;
typedef unsigned long Window;
Expand All @@ -34,6 +31,9 @@ typedef void *EGLConfig;
typedef void *EGLSurface;
typedef void *EGLContext;

typedef std::map<EGLint,EGLint> ofEGLAttributeList;
typedef std::map<EGLint,EGLint>::iterator ofEGLAttributeListIterator;

struct ofAppEGLWindowSettings: public ofGLESWindowSettings {
public:
ofAppEGLWindowType eglWindowPreference; ///< what window type is preferred?
Expand Down Expand Up @@ -119,7 +119,7 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread {
EGLSurface getEglSurface() const;
EGLContext getEglContext() const;

#ifndef TARGET_RASPBERRY_PI
#ifndef TARGET_RASPBERRY_PI_LEGACY
Display* getX11Display();
Window getX11Window();
#endif
Expand Down Expand Up @@ -225,7 +225,7 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread {
EGLNativeWindowType getNativeWindow();
EGLNativeDisplayType getNativeDisplay();

#ifdef TARGET_RASPBERRY_PI
#ifdef TARGET_RASPBERRY_PI_LEGACY
void initRPiNative();
void exitRPiNative();

Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/app/ofAppGLFWWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ void ofAppGLFWWindow::makeCurrent(){
glfwMakeContextCurrent(windowP);
}

#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI)
#if defined(TARGET_LINUX)
Display* ofAppGLFWWindow::getX11Display(){
return glfwGetX11Display();
}
Expand Down
6 changes: 3 additions & 3 deletions libs/openFrameworks/app/ofAppGLFWWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ofAppBaseWindow.h"
#include "ofRectangle.h"

#ifdef TARGET_LINUX
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)
typedef struct _XIM * XIM;
typedef struct _XIC * XIC;
#endif
Expand Down Expand Up @@ -146,7 +146,7 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow {
OF_DEPRECATED_MSG("use ofGLFWWindowSettings to create the window instead", void setStencilBits(int stencil));
OF_DEPRECATED_MSG("use ofGLFWWindowSettings to create the window instead", void setMultiDisplayFullscreen(bool bMultiFullscreen)); //note this just enables the mode, you have to toggle fullscreen to activate it.

#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI)
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)
Display* getX11Display();
Window getX11Window();
XIC getX11XIC();
Expand Down Expand Up @@ -188,7 +188,7 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow {

void close();

#ifdef TARGET_LINUX
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)
void setWindowIcon(const std::string & path);
void setWindowIcon(const ofPixels & iconPixels);
XIM xim;
Expand Down
4 changes: 2 additions & 2 deletions libs/openFrameworks/app/ofAppRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using namespace std;

#if !defined( TARGET_OF_IOS ) & !defined(TARGET_ANDROID) & !defined(TARGET_EMSCRIPTEN) & !defined(TARGET_RASPBERRY_PI)
#if !defined( TARGET_OF_IOS ) & !defined(TARGET_ANDROID) & !defined(TARGET_EMSCRIPTEN) & !defined(TARGET_RASPBERRY_PI_LEGACY)
#include "ofAppGLFWWindow.h"
//special case so we preserve supplied settngs
//TODO: remove me when we remove the ofAppGLFWWindow setters.
Expand Down Expand Up @@ -471,7 +471,7 @@ void ofSetVerticalSync(bool bSync){
}

//-------------------------- native window handles
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI)
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)
Display* ofGetX11Display(){
return mainLoop()->getCurrentWindow()->getX11Display();
}
Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/app/ofAppRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ std::shared_ptr<ofBaseRenderer> & ofGetCurrentRenderer();
void ofSetEscapeQuitsApp(bool bQuitOnEsc);

//-------------------------- native window handles
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI)
#if defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)
typedef unsigned long Window;
struct _XDisplay;
typedef struct _XDisplay Display;
Expand Down
4 changes: 4 additions & 0 deletions libs/openFrameworks/app/ofMainLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "ofAppAndroidWindow.h"
#include "ofxAndroidUtils.h"
#include "ofxAndroidApp.h"
#elif defined(TARGET_RASPBERRY_PI) && defined(TARGET_GLFW_WINDOW)
#include "ofAppGLFWWindow.h"
#elif defined(TARGET_RASPBERRY_PI)
#include "ofAppEGLWindow.h"
#elif defined(TARGET_EMSCRIPTEN)
Expand Down Expand Up @@ -51,6 +53,8 @@ shared_ptr<ofAppBaseWindow> ofMainLoop::createWindow(const ofWindowSettings & se
shared_ptr<ofAppiOSWindow> window = std::make_shared<ofAppiOSWindow>();
#elif defined(TARGET_ANDROID)
shared_ptr<ofAppAndroidWindow> window = std::make_shared<ofAppAndroidWindow>();
#elif (defined(TARGET_RASPBERRY_PI) && defined(TARGET_GLFW_WINDOW))
shared_ptr<ofAppGLFWWindow> window = std::make_shared<ofAppGLFWWindow>();
#elif defined(TARGET_RASPBERRY_PI)
shared_ptr<ofAppEGLWindow> window = std::make_shared<ofAppEGLWindow>();
#elif defined(TARGET_EMSCRIPTEN)
Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/gl/ofGLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ int ofGetGLInternalFormatFromPixelFormat(ofPixelFormat pixelFormat){
return GL_RGB;
#endif
case OF_PIXELS_RGB565:
#if defined(TARGET_ANDROID) || defined(TARGET_RASPBERRY_PI)
#if defined(TARGET_ANDROID) || defined(TARGET_RASPBERRY_PI_LEGACY)
return GL_RGB565_OES;
#elif defined(GL_RGB565)
return GL_RGB565;
Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/ofMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
#include "ofAppBaseWindow.h"
#include "ofWindowSettings.h"
#include "ofMainLoop.h"
#if !defined( TARGET_OF_IOS ) & !defined(TARGET_ANDROID) & !defined(TARGET_EMSCRIPTEN) & !defined(TARGET_RASPBERRY_PI)
#if !defined( TARGET_OF_IOS ) & !defined(TARGET_ANDROID) & !defined(TARGET_EMSCRIPTEN) & !defined(TARGET_RASPBERRY_PI_LEGACY)
#include "ofAppGLFWWindow.h"
#if !defined( TARGET_LINUX_ARM )
#include "ofAppGlutWindow.h"
Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/utils/ofSystemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ gboolean text_dialog_gtk(gpointer userdata){
static void initGTK(){
static bool initialized = false;
if(!initialized){
#if !defined(TARGET_RASPBERRY_PI)
#if !defined(TARGET_RASPBERRY_PI_LEGACY)
XInitThreads();
#endif
int argc=0; char **argv = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/utils/ofTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void ofTimer::setPeriodicEvent(uint64_t nanoseconds){
}

void ofTimer::waitNext(){
#if (defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI))
#if (defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY))
timespec remainder = {0,0};
timespec wakeTime = nextWakeTime.getAsTimespec();
clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,&wakeTime,&remainder);
Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/utils/ofUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace priv{
ofTime t;
t.mode = mode;
if(mode == ofTime::System){
#if (defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI)) || defined(TARGET_EMSCRIPTEN)
#if (defined(TARGET_LINUX) && !defined(TARGET_RASPBERRY_PI_LEGACY)) || defined(TARGET_EMSCRIPTEN)
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
t.seconds = now.tv_sec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,42 @@ include $(OF_SHARED_MAKEFILES_PATH)/config.linux.common.mk
# Note: Leave a leading space when adding list items with the += operator
################################################################################

# We detect Raspbian versions Stretch and newer above and enable legacy automatically for older versions
# If detection fails comment USE_PI_LEGACY = 1 to use the newer system
USE_PI_LEGACY = 1

VER_ID = 0

#if we have this file lets see if we are Stretch or Newer
ifneq (,$(wildcard $(RPI_ROOT)/etc/os-release))
#grab the Debian version ( 9 = Stretch, 10 = Buster )
VER_ID = $(shell grep -oP '(?<=^VERSION_ID=).+' $(RPI_ROOT)/etc/os-release | tr -d '"')
endif

#check if we are newer than 8 and use the new system
ifeq ($(shell expr $(VER_ID) \>= 9), 1)
USE_PI_LEGACY = 0
endif

$(info VER ID IS $(VER_ID))

# defines used inside openFrameworks libs.
PLATFORM_DEFINES += TARGET_RASPBERRY_PI

ifeq ($(USE_PI_LEGACY), 1)
PLATFORM_DEFINES += TARGET_RASPBERRY_PI_LEGACY
$(info using legacy build)
else
# comment this for older EGL windowing. Has no effect if USE_PI_LEGACY is enabled
# GLFW seems to provide a more robust window on newer Raspbian releases
USE_GLFW_WINDOW = 1
$(info using newer build and GLFW window)
endif

ifdef USE_GLFW_WINDOW
PLATFORM_DEFINES += TARGET_GLFW_WINDOW
endif

# TODO many of these are not relevant to openFrameworks (were just pasted from hello_pi examples)
# from raspberry pi examples
PLATFORM_DEFINES += STANDALONE
Expand Down Expand Up @@ -119,15 +152,28 @@ PLATFORM_CFLAGS += -pipe
# Note: Leave a leading space when adding list items with the += operator
################################################################################

#rpi4
ifdef USE_GLFW_WINDOW
PLATFORM_PKG_CONFIG_LIBRARIES += gl
PLATFORM_PKG_CONFIG_LIBRARIES += glu
PLATFORM_PKG_CONFIG_LIBRARIES += glew
PLATFORM_LIBRARIES += glfw
endif

# raspberry pi specific
ifneq (,$(wildcard $(RPI_ROOT)/opt/vc/lib/libGLESv2.so))
ifeq ($(USE_PI_LEGACY), 0)
PLATFORM_LIBRARIES += GLESv2
PLATFORM_LIBRARIES += GLESv1_CM
PLATFORM_LIBRARIES += EGL
else ifneq (,$(wildcard $(RPI_ROOT)/opt/vc/lib/libGLESv2.so))
PLATFORM_LIBRARIES += GLESv2
PLATFORM_LIBRARIES += GLESv1_CM
PLATFORM_LIBRARIES += EGL
else
PLATFORM_LIBRARIES += brcmGLESv2
PLATFORM_LIBRARIES += brcmEGL
endif

PLATFORM_LIBRARIES += openmaxil
PLATFORM_LIBRARIES += bcm_host
PLATFORM_LIBRARIES += vcos
Expand All @@ -137,9 +183,11 @@ PLATFORM_LIBRARIES += rt
PLATFORM_LIBRARIES += X11
PLATFORM_LIBRARIES += dl


PLATFORM_LDFLAGS += -pthread

ifeq ($(USE_PI_LEGACY), 0)
PLATFORM_LDFLAGS += -latomic
endif

################################################################################
# PLATFORM HEADER SEARCH PATHS
Expand Down Expand Up @@ -186,7 +234,12 @@ PLATFORM_LIBRARY_SEARCH_PATHS += $(RPI_ROOT)/opt/vc/lib
# Note: Leave a leading space when adding list items with the += operator
################################################################################

PLATFORM_CORE_EXCLUSIONS += $(OF_LIBS_PATH)/openFrameworks/app/ofAppGLFWWindow.cpp
#rpi4
ifndef USE_GLFW_WINDOW
PLATFORM_CORE_EXCLUSIONS += $(OF_LIBS_PATH)/openFrameworks/app/ofAppGLFWWindow.cpp
else
PLATFORM_CORE_EXCLUSIONS += $(OF_LIBS_PATH)/openFrameworks/app/ofAppEGLWindow.cpp
endif
PLATFORM_CORE_EXCLUSIONS += $(OF_LIBS_PATH)/openFrameworks/sound/ofFmodSoundPlayer.cpp

ifeq ($(CROSS_COMPILING),1)
Expand Down
Loading

0 comments on commit 261af06

Please sign in to comment.