tangrams / tangram-es

2D and 3D map renderer using OpenGL ES
MIT License
826 stars 238 forks source link

Build errors on Raspberry Pi 3 B+ (Raspbian GNU/Linux 11 (bullseye)) #2314

Open shenzhuxi opened 2 years ago

shenzhuxi commented 2 years ago

TO REPRODUCE THE ISSUE, FOLLOW THESE STEPS:

RESULT:

In file included from /usr/include/X11/Xlib.h:44,
                 from /usr/include/EGL/eglplatform.h:128,
                 from /usr/include/EGL/egl.h:39,
                 from /home/pi/Documents/tangram-es/platforms/common/platform_gl.h:63,
                 from /home/pi/Documents/tangram-es/platforms/rpi/src/context.h:3,
                 from /home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:1:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:42:44: error: expected identifier before numeric constant
   42 |     enum { FontPath, FontName, FontLoader, None } tag = None;
      |                                            ^~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:42:44: error: expected '}' before numeric constant
In file included from /home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:2:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:42:10: note: to match this '{'
   42 |     enum { FontPath, FontName, FontLoader, None } tag = None;
      |          ^
In file included from /usr/include/X11/Xlib.h:44,
                 from /usr/include/EGL/eglplatform.h:128,
                 from /usr/include/EGL/egl.h:39,
                 from /home/pi/Documents/tangram-es/platforms/common/platform_gl.h:63,
                 from /home/pi/Documents/tangram-es/platforms/rpi/src/context.h:3,
                 from /home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:1:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:42:44: error: expected unqualified-id before numeric constant
   42 |     enum { FontPath, FontName, FontLoader, None } tag = None;
      |                                            ^~~~
In file included from /home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:2:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h: In constructor 'Tangram::FontSourceHandle::FontSourceHandle(Tangram::Url)':
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:38:43: error: class 'Tangram::FontSourceHandle' does not have any field named 'fontPath'
   38 |     explicit FontSourceHandle(Url path) : fontPath(path) { tag = FontPath; }
      |                                           ^~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:38:60: error: 'tag' was not declared in this scope
   38 |     explicit FontSourceHandle(Url path) : fontPath(path) { tag = FontPath; }
      |                                                            ^~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h: In constructor 'Tangram::FontSourceHandle::FontSourceHandle(std::string)':
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:39:51: error: class 'Tangram::FontSourceHandle' does not have any field named 'fontName'
   39 |     explicit FontSourceHandle(std::string name) : fontName(name) { tag = FontName; }
      |                                                   ^~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:39:68: error: 'tag' was not declared in this scope
   39 |     explicit FontSourceHandle(std::string name) : fontName(name) { tag = FontName; }
      |                                                                    ^~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h: In constructor 'Tangram::FontSourceHandle::FontSourceHandle(Tangram::FontSourceLoader)':
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:40:58: error: class 'Tangram::FontSourceHandle' does not have any field named 'fontLoader'
   40 |     explicit FontSourceHandle(FontSourceLoader loader) : fontLoader(loader) { tag = FontLoader; }
      |                                                          ^~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:40:79: error: 'tag' was not declared in this scope
   40 |     explicit FontSourceHandle(FontSourceLoader loader) : fontLoader(loader) { tag = FontLoader; }
      |                                                                               ^~~
In file included from /usr/include/X11/Xlib.h:44,
                 from /usr/include/EGL/eglplatform.h:128,
                 from /usr/include/EGL/egl.h:39,
                 from /home/pi/Documents/tangram-es/platforms/common/platform_gl.h:63,
                 from /home/pi/Documents/tangram-es/platforms/rpi/src/context.h:3,
                 from /home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:1:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h: At global scope:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:42:57: error: conversion from 'long int' to non-scalar type 'Tangram::FontSourceHandle' requested
   42 |     enum { FontPath, FontName, FontLoader, None } tag = None;
      |                                                         ^~~~
In file included from /home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:2:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:47:20: error: non-member function 'bool Tangram::isValid()' cannot have cv-qualifier
   47 |     bool isValid() const { return tag != None; }
      |                    ^~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h: In function 'bool Tangram::isValid()':
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:47:39: error: no match for 'operator!=' (operand types are 'Tangram::FontSourceHandle' and 'long int')
   47 |     bool isValid() const { return tag != None; }
      |                                   ~~~ ^~
      |                                   |
      |                                   Tangram::FontSourceHandle
/home/pi/Documents/tangram-es/core/include/tangram/platform.h: At global scope:
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:82:5: error: 'UrlRequestHandle' does not name a type
   82 |     UrlRequestHandle startUrlRequest(Url _url, UrlCallback&& _callback);
      |     ^~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:87:27: error: 'UrlRequestHandle' has not been declared
   87 |     void cancelUrlRequest(UrlRequestHandle _request);
      |                           ^~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:89:13: error: 'FontSourceHandle' does not name a type
   89 |     virtual FontSourceHandle systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) const;
      |             ^~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:91:25: error: 'FontSourceHandle' was not declared in this scope; did you mean 'Tangram::FontSourceHandle'?
   91 |     virtual std::vector<FontSourceHandle> systemFontFallbacksHandle() const;
      |                         ^~~~~~~~~~~~~~~~
      |                         Tangram::FontSourceHandle
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:33:8: note: 'Tangram::FontSourceHandle' declared here
   33 | struct FontSourceHandle {
      |        ^~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:91:41: error: template argument 1 is invalid
   91 |     virtual std::vector<FontSourceHandle> systemFontFallbacksHandle() const;
      |                                         ^
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:91:41: error: template argument 2 is invalid
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:101:24: error: 'UrlRequestHandle' has not been declared
  101 |     void onUrlResponse(UrlRequestHandle _request, UrlResponse&& _response);
      |                        ^~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:101:51: error: 'UrlResponse' has not been declared
  101 |     void onUrlResponse(UrlRequestHandle _request, UrlResponse&& _response);
      |                                                   ^~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:106:44: error: 'Url' does not name a type
  106 |     virtual bool startUrlRequestImpl(const Url& _url, UrlRequestHandle _request, UrlRequestId& _id) = 0;
      |                                            ^~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:106:55: error: 'UrlRequestHandle' has not been declared
  106 |     virtual bool startUrlRequestImpl(const Url& _url, UrlRequestHandle _request, UrlRequestId& _id) = 0;
      |                                                       ^~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:116:9: error: 'UrlCallback' does not name a type; did you mean 'XICCallback'?
  116 |         UrlCallback callback;
      |         ^~~~~~~~~~~
      |         XICCallback
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:120:24: error: 'UrlRequestHandle' was not declared in this scope; did you mean 'Tangram::UrlRequestHandle'?
  120 |     std::unordered_map<UrlRequestHandle, UrlRequestEntry> m_urlCallbacks;
      |                        ^~~~~~~~~~~~~~~~
      |                        Tangram::UrlRequestHandle
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:16:7: note: 'Tangram::UrlRequestHandle' declared here
   16 | using UrlRequestHandle = uint64_t;
      |       ^~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:120:57: error: template argument 1 is invalid
  120 |     std::unordered_map<UrlRequestHandle, UrlRequestEntry> m_urlCallbacks;
      |                                                         ^
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:120:57: error: template argument 3 is invalid
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:120:57: error: template argument 4 is invalid
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:120:57: error: template argument 5 is invalid
/home/pi/Documents/tangram-es/core/include/tangram/platform.h:124:1: error: expected declaration before '}' token
  124 | } // namespace Tangram
      | ^
/home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp: In function 'void createSurface(int, int, int, int)':
/home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:325:43: warning: invalid conversion from 'int' to 'DISPMANX_FLAGS_ALPHA_T' [-fpermissive]
  325 |     VC_DISPMANX_ALPHA_T dispman_alpha = { 0 };
      |                                           ^
      |                                           |
      |                                           int
/home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:328:26: warning: converting to non-pointer type 'DISPMANX_RESOURCE_HANDLE_T' {aka 'unsigned int'} from NULL [-Wconversion-null]
  328 |     dispman_alpha.mask = NULL;
      |                          ^~~~
/home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:348:12: error: 'EGL_DISPMANX_WINDOW_T' does not name a type
  348 |     static EGL_DISPMANX_WINDOW_T native_window = { 0 };
      |            ^~~~~~~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:349:5: error: 'native_window' was not declared in this scope
  349 |     native_window.element = dispman_element;
      |     ^~~~~~~~~~~~~
/home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:297:13: warning: unused variable 'success' [-Wunused-variable]
  297 |     int32_t success = graphics_get_display_size(0, &screen_width, &screen_height);
      |             ^~~~~~~
In file included from /home/pi/Documents/tangram-es/platforms/rpi/src/context.h:3,
                 from /home/pi/Documents/tangram-es/platforms/rpi/src/context.cpp:1:
/home/pi/Documents/tangram-es/platforms/common/platform_gl.h: At global scope:
/home/pi/Documents/tangram-es/platforms/common/platform_gl.h:69:13: warning: 'void glGenVertexArrays(GLsizei, GLuint*)' defined but not used [-Wunused-function]
   69 | static void glGenVertexArrays(GLsizei n, GLuint *arrays) {}
      |             ^~~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/platforms/common/platform_gl.h:68:13: warning: 'void glDeleteVertexArrays(GLsizei, const GLuint*)' defined but not used [-Wunused-function]
   68 | static void glDeleteVertexArrays(GLsizei n, const GLuint *arrays) {}
      |             ^~~~~~~~~~~~~~~~~~~~
/home/pi/Documents/tangram-es/platforms/common/platform_gl.h:67:13: warning: 'void glBindVertexArray(GLuint)' defined but not used [-Wunused-function]
   67 | static void glBindVertexArray(GLuint array) {}
      |             ^~~~~~~~~~~~~~~~~
gmake[3]: *** [CMakeFiles/tangram.dir/build.make:82: CMakeFiles/tangram.dir/platforms/rpi/src/context.cpp.o] Error 1
gmake[3]: Leaving directory '/home/pi/Documents/tangram-es/build/rpi'
gmake[2]: *** [CMakeFiles/Makefile2:340: CMakeFiles/tangram.dir/all] Error 2
gmake[2]: Leaving directory '/home/pi/Documents/tangram-es/build/rpi'
gmake[1]: *** [Makefile:171: all] Error 2
gmake[1]: Leaving directory '/home/pi/Documents/tangram-es/build/rpi'
make: *** [Makefile:251: rpi] Error 2

EXPECTED RESULT:

There is no problem to build the main branch on Windows 10 with cmake -S . -B .\build -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="\scripts\buildsystems\vcpkg.cmake"

ENVIRONMENT:

OTHER:

It will be also good to add "sudo apt-get install libgles2-mesa-dev" to https://github.com/tangrams/tangram-es/tree/main/platforms/rpi.

I don't think "Visual Studio 16 2019" can be downloaded from https://visualstudio.microsoft.com/downloads/ and it will be good to update https://github.com/tangrams/tangram-es/tree/main/platforms/windows with:

cmake -S . -B .\build -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="\scripts\buildsystems\vcpkg.cmake"

matteblair commented 2 years ago

Thanks for the report. Can you tell me the compiler version that you are using on your Raspberry Pi?

shenzhuxi commented 2 years ago

Package: gcc Version: 4:10.2.1-1+rpi1 Priority: optional Section: devel Source: gcc-defaults (1.190+rpi1) Maintainer: Debian GCC Maintainers debian-gcc@lists.debian.org Installed-Size: 46.1 kB Provides: c-compiler, gcc-arm-linux-gnueabihf (= 4:10.2.1-1+rpi1) Depends: cpp (= 4:10.2.1-1+rpi1), gcc-10 (>= 10.2.1-3~)

Package: g++ Version: 4:10.2.1-1+rpi1 Priority: optional Section: devel Source: gcc-defaults (1.190+rpi1) Maintainer: Debian GCC Maintainers debian-gcc@lists.debian.org Installed-Size: 15.4 kB Provides: c++-compiler, g++-arm-linux-gnueabihf (= 4:10.2.1-1+rpi1) Depends: cpp (= 4:10.2.1-1+rpi1), gcc (= 4:10.2.1-1+rpi1), g++-10 (>= 10.2.1-3~), gcc-10 (>= 10.2.1-3~)

Package: cmake Version: 3.18.4-2+rpt1+rpi1 Priority: optional Section: devel Maintainer: Debian CMake Team pkg-cmake-team@lists.alioth.debian.org Installed-Size: 18.3 MB Depends: cmake-data (= 3.18.4-2+rpt1+rpi1), procps, libarchive13 (>= 3.3.3), libc6 (>= 2.28), libcurl4 (>= 7.16.2), libexpat1 (>= 2.0.1), libgcc-s1 (>= 3.5), libjsoncpp24 (>= 1.9.4), librhash0 (>= 1.2.6), libstdc++6 (>= 9), libuv1 (>= 1.11.0), zlib1g (>= 1:1.2.3.3)

Package: make Version: 4.3-4.1

shenzhuxi commented 2 years ago

I just finished building on Raspberry with "make linux" by following https://github.com/tangrams/tangram-es/tree/main/platforms/linux and adding "-latomic" to https://github.com/tangrams/tangram-es/blob/main/platforms/linux/config.cmake.

Two variables GLintptr and GLsizeiptr need to be renamed to avoid the name conflicts.

diff --git a/core/src/gl.h b/core/src/gl.h
index 91810b55..3ce36315 100644
--- a/core/src/gl.h
+++ b/core/src/gl.h
@@ -8,8 +8,8 @@ typedef signed long int  GLintptr;
 typedef signed long int  GLsizeiptr;
 #else
 #include <stddef.h>
-typedef ptrdiff_t GLsizeiptr;
-typedef ptrdiff_t GLintptr;
+typedef ptrdiff_t GLsizeiptr2;
+typedef ptrdiff_t GLintptr2;
 #endif

 /*
@@ -323,8 +323,8 @@ struct GL {
     static void bindBuffer(GLenum target, GLuint buffer);
     static void deleteBuffers(GLsizei n, const GLuint *buffers);
     static void genBuffers(GLsizei n, GLuint *buffers);
-    static void bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage);
-    static void bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
+    static void bufferData(GLenum target, GLsizeiptr2 size, const void *data, GLenum usage);
+    static void bufferSubData(GLenum target, GLintptr2 offset, GLsizeiptr2 size, const void *data);

     // Framebuffers
     static void bindFramebuffer(GLenum target, GLuint framebuffer);
diff --git a/core/src/gl/mesh.cpp b/core/src/gl/mesh.cpp
index 2410dacf..6facf952 100644
--- a/core/src/gl/mesh.cpp
+++ b/core/src/gl/mesh.cpp
@@ -254,7 +254,7 @@ size_t MeshBase::compileIndices(const std::vector<std::pair<uint32_t, uint32_t>>
     return _offset + src;
 }

-void MeshBase::setDirty(GLintptr _byteOffset, GLsizei _byteSize) {
+void MeshBase::setDirty(GLintptr2 _byteOffset, GLsizei _byteSize) {

     if (!m_dirty) {
         m_dirty = true;
diff --git a/core/src/gl/mesh.h b/core/src/gl/mesh.h
index 2cfc72bf..12439eef 100644
--- a/core/src/gl/mesh.h
+++ b/core/src/gl/mesh.h
@@ -104,12 +104,12 @@ protected:
     RenderState* m_rs = nullptr;

     GLsizei m_dirtySize;
-    GLintptr m_dirtyOffset;
+    GLintptr2 m_dirtyOffset;

     size_t compileIndices(const std::vector<std::pair<uint32_t, uint32_t>>& _offsets,
                           const std::vector<uint16_t>& _indices, size_t _offset);

-    void setDirty(GLintptr _byteOffset, GLsizei _byteSize);
+    void setDirty(GLintptr2 _byteOffset, GLsizei _byteSize);
 };

 template<class T>
diff --git a/platforms/common/platform_gl.cpp b/platforms/common/platform_gl.cpp
index 93c46004..7271c033 100644
--- a/platforms/common/platform_gl.cpp
+++ b/platforms/common/platform_gl.cpp
@@ -142,10 +142,10 @@ void GL::deleteBuffers(GLsizei n, const GLuint *buffers) {
 void GL::genBuffers(GLsizei n, GLuint *buffers) {
     GL_CHECK(glGenBuffers(n, buffers));
 }
-void GL::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) {
+void GL::bufferData(GLenum target, GLsizeiptr2 size, const void *data, GLenum usage) {
     GL_CHECK(glBufferData(target, size, data, usage));
 }
-void GL::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) {
+void GL::bufferSubData(GLenum target, GLintptr2 offset, GLsizeiptr2 size, const void *data) {
     GL_CHECK(glBufferSubData(target, offset, size, data));
 }
 void GL::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,

But the performance is quite bad. I guess that's because OpenGL can't run as fast as OpenGL ES on Raspberry Pi.

shenzhuxi commented 2 years ago

2314.patch.txt Here is the patch fixed the the most problems except this bit:

/usr/bin/ld: CMakeFiles/tangram.dir/platforms/common/platform_gl.cpp.o: in function `Tangram::GL::mapBuffer(unsigned int, unsigned int)':
platform_gl.cpp:(.text+0x134): undefined reference to `glMapBufferOES'
/usr/bin/ld: CMakeFiles/tangram.dir/platforms/common/platform_gl.cpp.o: in function `Tangram::GL::unmapBuffer(unsigned int)':
platform_gl.cpp:(.text+0x144): undefined reference to `glUnmapBufferOES'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/tangram.dir/build.make:202: tangram] Error 1
gmake[3]: Leaving directory '/home/pi/Documents/tangram-es/build/rpi'
gmake[2]: *** [CMakeFiles/Makefile2:340: CMakeFiles/tangram.dir/all] Error 2
gmake[2]: Leaving directory '/home/pi/Documents/tangram-es/build/rpi'
gmake[1]: *** [Makefile:171: all] Error 2
gmake[1]: Leaving directory '/home/pi/Documents/tangram-es/build/rpi'
make: *** [Makefile:251: rpi] Error 2

After "sudo rpi-update" update the firmware, this bit has been fixed in https://github.com/tangrams/tangram-es/blob/main/platforms/rpi/config.cmake by using

target_link_libraries(tangram
  PRIVATE
  tangram-core
  ${FONTCONFIG_LDFLAGS}
  curl
  pthread
  rt
  /opt/vc/lib/libbcm_host.so
  /opt/vc/lib/libbrcmEGL.so
  /opt/vc/lib/libbrcmGLESv2.so
  /opt/vc/lib/libvchiq_arm.so
  /opt/vc/lib/libvcos.so
  -latomic
)

After built it successfully, I got the same "* failed to add service - already in use?" issue here https://github.com/tangrams/tangram-es/issues/2214 when run it.