Skip to content

supports the Rpi 4 with EGL and GLFW. Closes #6436 #6438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) || defined(TARGET_RASPBERRY_PI_4))
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) || defined(TARGET_RASPBERRY_PI_4))
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
#if (!defined(TARGET_RASPBERRY_PI) || defined(TARGET_RASPBERRY_PI_4))
//------------------------------------------------------------
Display* ofAppEGLWindow::getX11Display(){
return x11Display;
Expand Down Expand Up @@ -315,14 +315,14 @@ EGLint ofAppEGLWindow::getEglVersionMinor() const {

//------------------------------------------------------------
void ofAppEGLWindow::initNative() {
#ifdef TARGET_RASPBERRY_PI
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
initRPiNative();
#endif
}

//------------------------------------------------------------
void ofAppEGLWindow::exitNative() {
#ifdef TARGET_RASPBERRY_PI
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
exitRPiNative();
#endif
}
Expand All @@ -337,7 +337,7 @@ EGLNativeWindowType ofAppEGLWindow::getNativeWindow() {
if(isUsingX11) {
return (EGLNativeWindowType)x11Window;
} else {
#ifdef TARGET_RASPBERRY_PI
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))

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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))

// 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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
//------------------------------------------------------------
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
#if (!defined(TARGET_RASPBERRY_PI) || defined(TARGET_RASPBERRY_PI_4))
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
#if (defined(TARGET_RASPBERRY_PI) && !defined(TARGET_RASPBERRY_PI_4))
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) || defined(TARGET_RASPBERRY_PI_4))
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) || defined(TARGET_RASPBERRY_PI_4) )
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) || defined(TARGET_RASPBERRY_PI_4))
void setWindowIcon(const std::string & path);
void setWindowIcon(const ofPixels & iconPixels);
XIM xim;
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) && !defined(TARGET_RASPBERRY_PI_4))
return GL_RGB565_OES;
#elif defined(GL_RGB565)
return GL_RGB565;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ include $(OF_SHARED_MAKEFILES_PATH)/config.linux.common.mk
# defines used inside openFrameworks libs.
PLATFORM_DEFINES += TARGET_RASPBERRY_PI

# this needs to be set for rpi 4 and newer
# note this only works with the new GL driver and not the Legacy driver ( set with: sudo raspi-config )

# TODO: detect rpi4 or newer by parsing /proc/device-tree/model
IS_RPI_4_NEWER = 1

# uncomment this for glfw windowing on rpi 4 and newer
#USE_GLFW_WINDOW = 1;

ifdef IS_RPI_4_NEWER
PLATFORM_DEFINES += TARGET_RASPBERRY_PI_4
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 +136,27 @@ 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
endif

# raspberry pi specific
ifneq (,$(wildcard $(RPI_ROOT)/opt/vc/lib/libGLESv2.so))
ifdef IS_RPI_4_NEWER
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 @@ -140,6 +169,10 @@ PLATFORM_LIBRARIES += dl

PLATFORM_LDFLAGS += -pthread

#rpi4
ifdef IS_RPI_4_NEWER
PLATFORM_LDFLAGS += -latomic
endif

################################################################################
# PLATFORM HEADER SEARCH PATHS
Expand Down Expand Up @@ -186,7 +219,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
4 changes: 2 additions & 2 deletions scripts/linux/debian/install_dependencies.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fi


echo "installing OF dependencies"
apt-get install freeglut3-dev libasound2-dev libxmu-dev libxxf86vm-dev g++ libgl1-mesa-dev libglu1-mesa-dev libraw1394-dev libudev-dev libdrm-dev libglew-dev libopenal-dev libsndfile-dev libfreeimage-dev libcairo2-dev libfreetype6-dev libssl-dev libpulse-dev libusb-1.0-0-dev libgtk${GTK_VERSION}-dev libopencv-dev libegl1-mesa-dev libgles1-mesa-dev libgles2-mesa-dev libassimp-dev librtaudio-dev libboost-filesystem-dev libglfw3-dev liburiparser-dev libcurl4-openssl-dev libpugixml-dev libpoco-dev
apt-get install freeglut3-dev libasound2-dev libxmu-dev libxxf86vm-dev g++ libgl1-mesa-dev libglu1-mesa-dev libraw1394-dev libudev-dev libdrm-dev libglew-dev libopenal-dev libsndfile-dev libfreeimage-dev libcairo2-dev libfreetype6-dev libssl-dev libpulse-dev libusb-1.0-0-dev libgtk${GTK_VERSION}-dev libopencv-dev libegl1-mesa-dev libgles1 libgles2-mesa-dev libassimp-dev librtaudio-dev libboost-filesystem-dev libglfw3-dev liburiparser-dev libcurl4-openssl-dev libpugixml-dev libpoco-dev
exit_code=$?
if [ $exit_code != 0 ]; then
echo "error installing dependencies, there could be an error with your internet connection"
Expand Down Expand Up @@ -81,4 +81,4 @@ else
echo "Updating ofxOpenCV to use openCV4"
sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv\s/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4 /g' "$addons_dir/ofxOpenCv/addon_config.mk"
sed -i -E 's/ADDON_PKG_CONFIG_LIBRARIES =(.*)opencv$/ADDON_PKG_CONFIG_LIBRARIES =\1opencv4/g' "$addons_dir/ofxOpenCv/addon_config.mk"
fi
fi