Skip to content

Commit

Permalink
Raspberry Pi: Working on a native OpenGL ES 2.0 build
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 4, 2020
1 parent 661ccaf commit f9199b3
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 100 deletions.
2 changes: 2 additions & 0 deletions doomsday/cmake/Config.cmake
Expand Up @@ -46,6 +46,8 @@ elseif (APPLE)
include (PlatformMacx)
elseif (WIN32)
include (PlatformWindows)
elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND EXISTS /opt/vc/include/bcm_host.h)
include (PlatformRaspberryPi)
else ()
include (PlatformUnix)
endif ()
Expand Down
47 changes: 47 additions & 0 deletions doomsday/cmake/PlatformRaspberryPi.cmake
@@ -0,0 +1,47 @@
# Raspberry Pi (no X11)
include (PlatformGenericUnix)

set (RASPBERRYPI YES)
set (DE_PLATFORM_SUFFIX raspi)
set (DE_AMETHYST_PLATFORM UNIX)

set (DE_BASE_DIR "" CACHE STRING "Base directory path (defaults to {prefix}/${DE_INSTALL_DATA_DIR})")
set (DE_LIBRARY_DIR "" CACHE STRING "Plugin directory path (defaults to {prefix}/${DE_INSTALL_PLUGIN_DIR})")

add_definitions (
-DDE_RASPBERRYPI
-D__USE_BSD
-D_GNU_SOURCE=1
-DDE_PLATFORM_ID="source"
)

if (CMAKE_COMPILER_IS_GNUCXX)
set (cxxOpts
-Wno-psabi
)
foreach (cxxOpt ${cxxOpts})
append_unique (CMAKE_CXX_FLAGS ${cxxOpt})
endforeach (cxxOpt)

# The tree FRE optimization causes crashes with GCC 6 (Yakkety).
append_unique (CMAKE_CXX_FLAGS_RELEASE -fno-tree-fre)
append_unique (CMAKE_CXX_FLAGS_RELWITHDEBINFO -fno-tree-fre)
append_unique (CMAKE_CXX_FLAGS_MINSIZEREL -fno-tree-fre)
endif ()

# All symbols are hidden by default.
append_unique (CMAKE_C_FLAGS "-fvisibility=hidden")
append_unique (CMAKE_CXX_FLAGS "-fvisibility=hidden")

# Broadcom Videocore IV OpenGL ES library.
if (NOT TARGET bcm)
add_library (bcm INTERFACE)
target_link_libraries (bcm INTERFACE
-L/opt/vc/lib
/opt/vc/lib/libGLESv2_static.a
brcmEGL
brcmGLESv2
vcos
m
)
endif ()
2 changes: 1 addition & 1 deletion doomsday/cmake/PlatformUnix.cmake
Expand Up @@ -29,7 +29,7 @@ else ()
endif ()

if (CMAKE_COMPILER_IS_GNUCXX)
foreach (cxxOpt -Wno-deprecated-copy;-Wno-class-memaccess;-Wno-address-of-packed-member)
foreach (cxxOpt -Wno-deprecated-copy;-Wno-class-memaccess;-Wno-address-of-packed-member;-Wno-psabi)
append_unique (CMAKE_CXX_FLAGS ${cxxOpt})
endforeach (cxxOpt)

Expand Down
1 change: 1 addition & 0 deletions doomsday/libs/core/CMakeLists.txt
Expand Up @@ -88,6 +88,7 @@ if (UNIX AND NOT APPLE)
-DDE_BASE_DIR="${baseDir}"
-DDE_LIBRARY_DIR="${libDir}"
)
target_link_libraries (libcore PRIVATE atomic)
endif ()
if (WIN32)
# timeBeginPeriod, timeEndPeriod
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/doomsday/src/filesys/zip.cpp
Expand Up @@ -627,7 +627,7 @@ size_t Zip::readLump(int lumpIndex, uint8_t *buffer, size_t startOffset,
LOGDEV_RES_XVERBOSE("\"%s:%s\" (%u bytes%s) [%u +%u]",
NativePath(composePath()).pretty()
<< NativePath(lumpFile.composePath()).pretty()
<< (unsigned long) lumpFile.size()
<< dsize(lumpFile.size())
<< (lumpFile.isCompressed()? ", compressed" : "")
<< startOffset
<< length);
Expand Down
20 changes: 15 additions & 5 deletions doomsday/libs/gui/CMakeLists.txt
Expand Up @@ -38,29 +38,36 @@ deng_merge_sources (text src/text/*.cpp)
deng_merge_sources (vr src/vr/*.cpp)
deng_merge_sources (widgets src/widgets/*.cpp)

list (APPEND SOURCES src/dialogs/filedialog_${DE_PLATFORM_SUFFIX})
if (DE_X11 OR RASPBERRYPI)
list (APPEND SOURCES src/dialogs/filedialog_generic.cpp)
else ()
list (APPEND SOURCES src/dialogs/filedialog_${DE_PLATFORM_SUFFIX})
endif ()

deng_add_library (libgui ${SOURCES} ${HEADERS})

if (DE_OPENGL_API STREQUAL "3.3")
target_compile_definitions (libgui PUBLIC -DDE_OPENGL=330)
message (STATUS "Using OpenGL 3.3")
set (DE_HAVE_OPENGL_ES NO)
elseif (DE_OPENGL_API STREQUAL "GLES3")
target_compile_definitions (libgui PUBLIC -DDE_OPENGL_ES=30)
message (STATUS "Using OpenGL ES 3.0")
set (DE_HAVE_OPENGL_ES YES)
elseif (DE_OPENGL_API STREQUAL "GLES2")
target_compile_definitions (libgui PUBLIC -DDE_OPENGL_ES=20)
message (STATUS "Using OpenGL ES 2.0")
set (DE_HAVE_OPENGL_ES YES)
else ()
message (FATAL_ERROR "Invalid value for OpenGL API: ${DE_OPENGL_API}")
endif ()

# Link libraries.
deng_link_libraries (libgui PUBLIC DengCore)
target_link_libraries (libgui
PUBLIC glbinding::glbinding
PRIVATE SDL2 stb assimp
)
target_link_libraries (libgui PRIVATE SDL2 stb assimp)
if (NOT DE_HAVE_OPENGL_ES)
target_link_libraries (libgui PUBLIC glbinding::glbinding)
endif ()
if (WIN32)
target_link_libraries (libgui PUBLIC opengl32.lib)
# Direct2D was used for DPI information.
Expand All @@ -77,6 +84,9 @@ elseif (APPLE)
link_framework (libgui PRIVATE Cocoa)
link_framework (libgui PRIVATE OpenGL)
endif ()
if (RASPBERRYPI)
target_link_libraries (libgui PRIVATE bcm)
endif ()

deng_deploy_library (libgui DengGui)

Expand Down
2 changes: 2 additions & 0 deletions doomsday/libs/gui/include/de/graphics/glbuffer.h
Expand Up @@ -358,7 +358,9 @@ class LIBGUI_PUBLIC GLBuffer : public Asset

enum Type {
VertexArray, // array buffer, or an array buffer with element array buffer
#if defined (DE_HAVE_TEXTURE_BUFFER)
Texture, // texture buffer
#endif
};

public:
Expand Down
22 changes: 16 additions & 6 deletions doomsday/libs/gui/include/de/graphics/glframebuffer.h
Expand Up @@ -45,15 +45,19 @@ class LIBGUI_PUBLIC GLFramebuffer : public Asset

enum Flag {
Color0 = 0x001, ///< Target has a color attachment.
#if defined (DE_HAVE_COLOR_ATTACHMENTS)
Color1 = 0x002,
Color2 = 0x004,
Color3 = 0x008,
#endif
Depth = 0x100, ///< Target has a depth attachment.
Stencil = 0x200, ///< Target has a stencil attachment.

Changed = 0x1000, ///< Draw/clear has occurred on the target.

#if defined (DE_HAVE_COLOR_ATTACHMENTS)
ColorAny = Color0 | Color1 | Color2 | Color3,
#endif
ColorDepth = Color0 | Depth,
ColorDepthStencil = Color0 | Depth | Stencil,
ColorStencil = Color0 | Stencil,
Expand Down Expand Up @@ -138,18 +142,22 @@ class LIBGUI_PUBLIC GLFramebuffer : public Asset
* Reconfigures the render target with two textures, one for the color
* values and one for depth/stencil values.
*
* If @a colorTex or @a depthStencilTex is omitted, a renderbuffer will be
* created in its place (depending on @a missingRenderBuffers).
* If @a colorTex, @a depthTex, or @a stencilTex is omitted, a renderbuffer
* will be created in its place (depending on @a missingRenderBuffers).
* @a depthTex and @a stencilTex can point to the same texture, in which
* case a combined depth/stencil attachment is used.
*
* Any previous attachments are released.
*
* @param colorTex Texture for color values.
* @param depthStencilTex Texture for depth/stencil values.
* @param depthTex Texture for depth values.
* @param stencilTex Texture for stencil values.
* @param missingRenderBuffers Create renderbuffers for attachments where
* texture has not been specified.
*/
void configure(GLTexture *colorTex,
GLTexture *depthStencilTex,
GLTexture *depthTex,
GLTexture *stencilTex,
Flags missingRenderBuffers = ColorDepthStencil);

/**
Expand All @@ -159,12 +167,14 @@ class LIBGUI_PUBLIC GLFramebuffer : public Asset
* created in its place (depending on @a missingRenderBuffers).
*
* @param colorTextures Textures for color attachments.
* @param depthStencilTex Texture for depth/stencil values.
* @param depthTex Texture for depth values.
* @param stencilTex Texture for stencil values.
* @param missingRenderBuffers Create renderbuffers for attachments where
* texture has not been specified.
*/
void configure(const List<GLTexture *> &colorTextures,
GLTexture * depthStencilTex,
GLTexture * depthTex,
GLTexture * stencilTex,
Flags missingRenderBuffers = ColorDepthStencil);

/**
Expand Down
13 changes: 4 additions & 9 deletions doomsday/libs/gui/include/de/graphics/opengl.h
Expand Up @@ -30,12 +30,6 @@
# include <glbinding/gl33core/gl.h>
# include <glbinding/gl33ext/enum.h>
using namespace gl33core;
//# include <QOpenGLFunctions_3_3_Core>
//# include <QOpenGLExtensions>
//# define QOpenGLFunctions_Doomsday QOpenGLFunctions_3_3_Core
//# ifndef GL_VERSION_3_3
//# error "OpenGL 3.3 (or newer) headers not found"
//# endif
# define DE_HAVE_TIMER_QUERY

#elif (DE_OPENGL_ES == 30)
Expand All @@ -44,9 +38,7 @@ using namespace gl33core;
# define QOpenGLFunctions_Doomsday QOpenGLExtraFunctions

#elif (DE_OPENGL_ES == 20)
# include <QOpenGLFunctions>
# include <QOpenGLExtensions>
# define QOpenGLFunctions_Doomsday QOpenGLFunctions
# include <SDL_opengles2.h>
#endif

// Defined in GLES2.
Expand All @@ -58,6 +50,9 @@ using namespace gl33core;
# define DE_HAVE_VAOS
# define DE_HAVE_INSTANCES
# define DE_HAVE_BLIT_FRAMEBUFFER
# define DE_HAVE_COLOR_ATTACHMENTS
# define DE_HAVE_DEPTH_STENCIL_ATTACHMENT
# define DE_HAVE_TEXTURE_BUFFER
#endif

#endif // LIBGUI_GRAPHICS_OPENGL_H
@@ -1,4 +1,4 @@
/** @file filedialog_x11.cpp Native file chooser dialog.
/** @file filedialog_generic.cpp File chooser dialog using Doomsday widgets.
*
* @authors Copyright (c) 2019 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand Down
66 changes: 51 additions & 15 deletions doomsday/libs/gui/src/graphics/glbuffer.cpp
Expand Up @@ -140,7 +140,9 @@ DE_PIMPL(GLBuffer)

Impl(Public *i, Type type)
: Base(i)
#if defined (DE_HAVE_TEXTURE_BUFFER)
, bufferType(type == Texture? GL_TEXTURE_BUFFER : GL_ARRAY_BUFFER)
#endif
{}

~Impl()
Expand Down Expand Up @@ -215,15 +217,28 @@ DE_PIMPL(GLBuffer)
{
switch (u)
{
case Static: return GL_STATIC_DRAW;
case StaticRead: return GL_STATIC_READ;
case StaticCopy: return GL_STATIC_COPY;
case Dynamic: return GL_DYNAMIC_DRAW;
case DynamicRead: return GL_DYNAMIC_READ;
case DynamicCopy: return GL_DYNAMIC_COPY;
case Stream: return GL_STREAM_DRAW;
case StreamRead: return GL_STREAM_READ;
case StreamCopy: return GL_STREAM_COPY;
#if defined (DE_OPENGL)
case Static: return GL_STATIC_DRAW;
case StaticRead: return GL_STATIC_READ;
case StaticCopy: return GL_STATIC_COPY;
case Dynamic: return GL_DYNAMIC_DRAW;
case DynamicRead: return GL_DYNAMIC_READ;
case DynamicCopy: return GL_DYNAMIC_COPY;
case Stream: return GL_STREAM_DRAW;
case StreamRead: return GL_STREAM_READ;
case StreamCopy: return GL_STREAM_COPY;
#endif
#if defined (DE_OPENGL_ES)
case Static: return GL_STATIC_DRAW;
case StaticRead: return GL_STATIC_DRAW;
case StaticCopy: return GL_STATIC_DRAW;
case Dynamic: return GL_DYNAMIC_DRAW;
case DynamicRead: return GL_DYNAMIC_DRAW;
case DynamicCopy: return GL_DYNAMIC_DRAW;
case Stream: return GL_STREAM_DRAW;
case StreamRead: return GL_STREAM_DRAW;
case StreamCopy: return GL_STREAM_DRAW;
#endif
}
DE_ASSERT_FAIL("Invalid glUsage");
return GL_STATIC_DRAW;
Expand Down Expand Up @@ -520,12 +535,13 @@ void GLBuffer::draw(const DrawRanges *ranges) const
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, d->idxName);
DE_ASSERT(GLProgram::programInUse()->validate());
#if defined (DE_OPENGL)
if (drawRanges.size() == 1)
{
glDrawElements(d->prim,
drawRanges.count[0],
GL_UNSIGNED_SHORT,
reinterpret_cast<const void *>(dintptr(drawRanges.first[0] * 2)));
drawRanges.count[0],
GL_UNSIGNED_SHORT,
reinterpret_cast<const void *>(dintptr(drawRanges.first[0] * 2)));
LIBGUI_ASSERT_GL_OK();
}
else
Expand All @@ -537,20 +553,32 @@ void GLBuffer::draw(const DrawRanges *ranges) const
}

glMultiDrawElements(d->prim,
drawRanges.count.data(),
GL_UNSIGNED_SHORT,
indices,
drawRanges.count.data(),
GL_UNSIGNED_SHORT,
indices,
GLsizei(drawRanges.size()));
LIBGUI_ASSERT_GL_OK();

delete [] indices;
}
#endif
#if defined (DE_OPENGL_ES)
for (duint i = 0; i < drawRanges.size(); ++i)
{
glDrawElements(d->prim,
drawRanges.count[i],
GL_UNSIGNED_SHORT,
reinterpret_cast<const void *>(dintptr(drawRanges.first[i] * 2)));
LIBGUI_ASSERT_GL_OK();
}
#endif

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
else
{
DE_ASSERT(GLProgram::programInUse()->validate());
#if defined (DE_OPENGL)
if (drawRanges.size() == 1)
{
glDrawArrays(d->prim, drawRanges.first[0], drawRanges.count[0]);
Expand All @@ -564,6 +592,14 @@ void GLBuffer::draw(const DrawRanges *ranges) const
GLsizei(drawRanges.size()));
LIBGUI_ASSERT_GL_OK();
}
#endif
#if defined (DE_OPENGL_ES)
for (duint i = 0; i < drawRanges.size(); ++i)
{
glDrawArrays(d->prim, drawRanges.first[i], drawRanges.count[i]);
LIBGUI_ASSERT_GL_OK();
}
#endif
}
++drawCounter;

Expand Down

0 comments on commit f9199b3

Please sign in to comment.