tcobbs/ldview

Build failure with GLES

Closed this issue · 9 comments

If Qt is build with GLES, LDView fails to build:

g++ -c -pipe   -std=c++11 -g -Wall -Wextra -D_REENTRANT -fPIC -DQT_THREAD_SUPPORT -D_QT -DQOFFSCREEN -DUSE_CPP11 -D_NO_BOOST -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I.. -I../include -I.ui -I/usr/include/QtOpenGL -I/usr/include/QtPrintSupport -I/usr/include/QtWidgets -I/usr/include/QtGui -I/usr/include/QtCore -I.moc -I.ui -I/usr/lib/mkspecs/linux-g++ -o .obj-qt5/LDViewSnapshotSettings.o LDViewSnapshotSettings.cpp
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from Preferences.cpp:17:
/usr/include/GLES3/gl32.h:481:28: error: conflicting declaration ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  481 | typedef void (GL_APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                            ^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../TRE/TREGLExtensions.h:6,
                 from Preferences.cpp:4:
../include/GL/glext.h:3528:25: note: previous declaration as ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar**, const GLint*)’
 3528 | typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length);
      |                         ^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from Preferences.cpp:17:
/usr/include/GLES3/gl32.h:624:29: error: conflicting declaration of C function ‘void glShaderSource(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  624 | GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                             ^~~~~~~~~~~~~~
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../TRE/TREGLExtensions.h:6,
                 from Preferences.cpp:4:
../include/GL/glext.h:3434:21: note: previous declaration ‘void glShaderSource(GLuint, GLsizei, const GLchar**, const GLint*)’
 3434 | GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *);
      |                     ^~~~~~~~~~~~~~
make[1]: *** [Makefile:2014: .obj-qt5/Preferences.o] Error 1
make[1]: *** Waiting for unfinished jobs....
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../LDLib/LDrawModelViewer.h:10,
                 from Preferences.h:5,
                 from ModelViewerWidget.h:18,
                 from LDViewExtraDir.cpp:6:
../include/GL/glext.h:3434:21: error: conflicting declaration of C function ‘void glShaderSource(GLuint, GLsizei, const GLchar**, const GLint*)’
 3434 | GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *);
      |                     ^~~~~~~~~~~~~~
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from LDViewExtraDir.cpp:6:
/usr/include/GLES3/gl32.h:624:29: note: previous declaration ‘void glShaderSource(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  624 | GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                             ^~~~~~~~~~~~~~
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../LDLib/LDrawModelViewer.h:10,
                 from Preferences.h:5,
                 from ModelViewerWidget.h:18,
                 from LDViewExtraDir.cpp:6:
../include/GL/glext.h:3528:25: error: conflicting declaration ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar**, const GLint*)’
 3528 | typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length);
      |                         ^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from LDViewExtraDir.cpp:6:
/usr/include/GLES3/gl32.h:481:28: note: previous declaration as ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  481 | typedef void (GL_APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                            ^~~~~~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:2116: .obj-qt5/LDViewExtraDir.o] Error 1
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../LDLib/LDrawModelViewer.h:10,
                 from Preferences.h:5,
                 from ModelViewerWidget.h:18,
                 from AlertHandler.cpp:2:
../include/GL/glext.h:3434:21: error: conflicting declaration of C function ‘void glShaderSource(GLuint, GLsizei, const GLchar**, const GLint*)’
 3434 | GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *);
      |                     ^~~~~~~~~~~~~~
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from AlertHandler.cpp:2:
/usr/include/GLES3/gl32.h:624:29: note: previous declaration ‘void glShaderSource(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  624 | GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                             ^~~~~~~~~~~~~~
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../LDLib/LDrawModelViewer.h:10,
                 from Preferences.h:5,
                 from ModelViewerWidget.h:18,
                 from AlertHandler.cpp:2:
../include/GL/glext.h:3528:25: error: conflicting declaration ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar**, const GLint*)’
 3528 | typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length);
      |                         ^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from AlertHandler.cpp:2:
/usr/include/GLES3/gl32.h:481:28: note: previous declaration as ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  481 | typedef void (GL_APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                            ^~~~~~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:2186: .obj-qt5/AlertHandler.o] Error 1
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../LDLib/LDrawModelViewer.h:10,
                 from Preferences.h:5,
                 from ModelViewerWidget.h:18,
                 from LDViewSnapshotSettings.cpp:5:
../include/GL/glext.h:3434:21: error: conflicting declaration of C function ‘void glShaderSource(GLuint, GLsizei, const GLchar**, const GLint*)’
 3434 | GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *);
      |                     ^~~~~~~~~~~~~~
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from LDViewSnapshotSettings.cpp:5:
/usr/include/GLES3/gl32.h:624:29: note: previous declaration ‘void glShaderSource(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  624 | GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                             ^~~~~~~~~~~~~~
In file included from /usr/include/GL/gl.h:2048,
                 from ../TRE/TREGL.h:27,
                 from ../LDLib/LDrawModelViewer.h:10,
                 from Preferences.h:5,
                 from ModelViewerWidget.h:18,
                 from LDViewSnapshotSettings.cpp:5:
../include/GL/glext.h:3528:25: error: conflicting declaration ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar**, const GLint*)’
 3528 | typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length);
      |                         ^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/QtGui/qopengl.h:105,
                 from /usr/include/QtOpenGL/qgl.h:45,
                 from ModelViewerWidget.h:9,
                 from LDViewSnapshotSettings.cpp:5:
/usr/include/GLES3/gl32.h:481:28: note: previous declaration as ‘typedef void (* PFNGLSHADERSOURCEPROC)(GLuint, GLsizei, const GLchar* const*, const GLint*)’
  481 | typedef void (GL_APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
      |                            ^~~~~~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:2256: .obj-qt5/LDViewSnapshotSettings.o] Error 1
make[1]: Leaving directory '/run/build/ldview/QT'
make: *** [Makefile:9: all] Error 2

@pbartfai I think you need to wrap the #include <GL/glext.h> lines in LDView with #ifndef GL_GLES_PROTOTYPES:

#ifndef GL_GLES_PROTOTYPES
#include <GL/glext.h>
#endif

There are three places: LDVExtensionsSetup.h, ModelWindow.h, and TREGL.h. It might make sense to only do this in TREGL.h, and update the other two headers to include <TRE/TREGL.h> instead of the GL headers. I don't have any way to replicate Hubert's environment.

I'll make a PR

It's not enough:

../TRE/TREGL.h:52:25: error: expected ‘)’ before ‘*’ token
   52 | typedef void * (APIENTRY * PFNWGLALLOCATEMEMORYNVPROC) (int size, float readfreq, float writefreq, float priority);
      |                ~        ^~
      |                         )

@hfiguiere I think you need to define APIENTRY to be (I'm guessing) GL_APIENTRY if you detect that GL_GLES_PROTOTYPES is defined. So change the #ifndef to #ifdef ... #else.

Further down the main problem is that GL_GLES_PROTOTYPES needs to be defined and this is done through one of the gl header, but in some places TREGL.h is included first with a note that it should be. (see QT/Preferences.cpp)

@pbartfai Is it possible for you to try to work this out?

@tcobbs most distros have Qt with GL. I do not know how to reproduce Qt with GLES only issue.
@hfiguiere please advise

Just as an aside, unless the GLES Qt back-fills missing functionality that is missing in GLES that is present in GL, LDView still won't build even if you get past these particular issues.

LDView uses a few functions from GLU (gluPerspective, gluBuild2DMipmaps, and gluOrtho2d), and GLU is not available for GLES. The code could in theory be rewritten to not use the GLU functions, but doing so would require knowledge of old OpenGL (1.0) and GLU in order to know what the functions are supposed to do in order to reimplement them.

For the context:
This is part of building LDView as a flatpak. No problem on x86_64, but the KDE SDK (which is the one that have Qt 5.15.3) is build on aarch64 with GLES. It seems that it is because otherwise it doesn't work on patform like pine64, but I can't confirm this. It's also somewhat out of my control.

Qt 5 doesn't allow having both GLES only and desktop GL, the later would work fine on Raspberry Pi.

For now, the aarch64 build will be disabled. And this is not unique to LDView.