Skip to content

Commit

Permalink
Raspberry Pi: Adapting libgui for OpenGL ES 2.0
Browse files Browse the repository at this point in the history
Disabling features not available in GLES2.
  • Loading branch information
skyjake committed Mar 5, 2020
1 parent f9199b3 commit ee23c88
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 48 deletions.
3 changes: 3 additions & 0 deletions doomsday/libs/gui/include/de/graphics/glinfo.h
Expand Up @@ -51,6 +51,9 @@ class LIBGUI_PUBLIC GLInfo
duint32 EXT_texture_compression_s3tc : 1;
duint32 EXT_texture_filter_anisotropic : 1;

// OpenGL ES extensions:
duint32 OES_rgb8_rgba8 : 1;

// Vendor-specific extensions:
duint32 NV_framebuffer_multisample_coverage : 1;
duint32 NV_texture_barrier : 1;
Expand Down
5 changes: 1 addition & 4 deletions doomsday/libs/gui/include/de/graphics/gltimer.h
Expand Up @@ -16,8 +16,7 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBGUI_GLTIMER_H
#define LIBGUI_GLTIMER_H
#pragma once

#include <de/Id>
#include "de/libgui.h"
Expand Down Expand Up @@ -72,5 +71,3 @@ class LIBGUI_PUBLIC GLTimer
};

} // namespace de

#endif // LIBGUI_GLTIMER_H
1 change: 1 addition & 0 deletions doomsday/libs/gui/include/de/graphics/opengl.h
Expand Up @@ -39,6 +39,7 @@ using namespace gl33core;

#elif (DE_OPENGL_ES == 20)
# include <SDL_opengles2.h>
# include <GLES2/gl2ext.h>
#endif

// Defined in GLES2.
Expand Down
64 changes: 41 additions & 23 deletions doomsday/libs/gui/src/graphics/glframebuffer.cpp
Expand Up @@ -39,6 +39,12 @@ static const int MAX_COLOR_ATTACHMENTS = 4;
static const int MAX_COLOR_ATTACHMENTS = 1;
#endif

#if (DE_OPENGL_ES == 20)
# define GL_DRAW_FRAMEBUFFER GL_FRAMEBUFFER
# define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER
# define GL_RGBA8 GL_RGBA8_OES
#endif

DE_PIMPL(GLFramebuffer)
, DE_OBSERVES(Asset, Deletion)
{
Expand Down Expand Up @@ -253,7 +259,11 @@ DE_PIMPL(GLFramebuffer)
DE_ASSERT(tex.isReady());
if (tex.isCubeMap())
{
glFramebufferTexture(FRAMEBUFFER_GL, attachment, tex.glName(), level);
#if defined (DE_OPENGL)
glFramebufferTexture(GL_FRAMEBUFFER, attachment, tex.glName(), level);
#else
DE_ASSERT_FAIL("Cannot attach cube map texture to framebuffer");
#endif
}
else
{
Expand All @@ -273,7 +283,7 @@ DE_PIMPL(GLFramebuffer)
glBindRenderbuffer(GL_RENDERBUFFER, renderBufs[id]);
LIBGUI_ASSERT_GL_OK();

#if !defined(DE_OPENGL_ES)
#if !defined (DE_OPENGL_ES)
if (sampleCount > 1)
{
if (GLInfo::extensions().NV_framebuffer_multisample_coverage)
Expand Down Expand Up @@ -342,11 +352,13 @@ DE_PIMPL(GLFramebuffer)
void allocRenderBuffers()
{
DE_ASSERT(size != nullSize);

// Fill in all the other requested attachments.
if (flags.testFlag(Color0) && !textureAttachment.testFlag(Color0))
{
/// @todo Note that for GLES, GL_RGBA8 is not supported (without an extension).
#if defined (DE_OPENGL_ES)
DE_ASSERT(GLInfo::extensions().OES_rgb8_rgba8);
#endif
LOG_GL_VERBOSE("FBO %i: color renderbuffer %s") << fbo << size.asText();
attachRenderbuffer(ColorBuffer0, GL_RGBA8, GL_COLOR_ATTACHMENT0);
}
Expand All @@ -356,9 +368,9 @@ DE_PIMPL(GLFramebuffer)
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}

#if defined (DE_HAVE_DEPTH_STENCIL_ATTACHMENT)
void allocDepthStencilRenderBuffers()
{
#if defined (DE_HAVE_DEPTH_STENCIL_ATTACHMENT)
if (flags.testFlag(DepthStencil) && !flags.testFlag(SeparateDepthAndStencil) &&
(!texture || textureAttachment == Color0))
{
Expand All @@ -367,23 +379,21 @@ DE_PIMPL(GLFramebuffer)
attachRenderbuffer(DepthStencilBuffer, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL_ATTACHMENT);
}
else
#endif // DE_HAVE_DEPTH_STENCIL_ATTACHMENT
{
// Separate depth and stencil, then.
if (flags.testFlag(Depth) && !textureAttachment.testFlag(Depth))
{
LOG_GL_VERBOSE("FBO %i: depth renderbuffer %s") << fbo << size.asText();
attachRenderbuffer(DepthBuffer, GL_DEPTH_COMPONENT, GL_DEPTH_ATTACHMENT);
}
#if defined (DE_OPENGL)
if (flags.testFlag(Stencil) && !textureAttachment.testFlag(Stencil))
{
LOG_GL_VERBOSE("FBO %i: stencil renderbuffer %s") << fbo << size.asText();
attachRenderbuffer(StencilBuffer, GL_STENCIL_INDEX, GL_STENCIL_ATTACHMENT);
}
#endif
}
}
#endif // DE_HAVE_DEPTH_STENCIL_ATTACHMENT

void deallocRenderBuffers()
{
Expand Down Expand Up @@ -479,28 +489,31 @@ DE_PIMPL(GLFramebuffer)
{
DE_ASSERT(fbo);

glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); LIBGUI_ASSERT_GL_OK();
// glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); LIBGUI_ASSERT_GL_OK();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
LIBGUI_ASSERT_GL_OK();

#if defined (DE_HAVE_COLOR_ATTACHMENTS)
const int count = colorAttachmentCount();

static const GLenum drawBufs[4] = {
GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3
};
glDrawBuffers(count, drawBufs); LIBGUI_ASSERT_GL_OK();
// glReadBuffer(count > 0? GL_COLOR_ATTACHMENT0 : GL_NONE); LIBGUI_ASSERT_GL_OK();
glDrawBuffers(count, drawBufs);
LIBGUI_ASSERT_GL_OK();
#endif
}

void glRelease() const
{
LIBGUI_ASSERT_GL_OK();

glBindFramebuffer(GL_DRAW_FRAMEBUFFER, defaultFramebuffer); // both read and write FBOs
// glBindFramebuffer(GL_READ_FRAMEBUFFER, defaultFramebuffer); // both read and write FBOs
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, defaultFramebuffer);
LIBGUI_ASSERT_GL_OK();

glDrawBuffer(GL_BACK); LIBGUI_ASSERT_GL_OK();
// glReadBuffer(GL_BACK); LIBGUI_ASSERT_GL_OK();
#if defined (DE_HAVE_COLOR_ATTACHMENTS)
glDrawBuffer(GL_BACK);
LIBGUI_ASSERT_GL_OK();
#endif
}

void validate()
Expand All @@ -512,9 +525,7 @@ DE_PIMPL(GLFramebuffer)
}

DE_ASSERT(fbo != 0);

//glBindFramebuffer(GL_FRAMEBUFFER, fbo);


glBind();

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
Expand Down Expand Up @@ -679,8 +690,8 @@ void GLFramebuffer::configure(const List<GLTexture *> &colorTextures,
d->attachRenderbuffer(Impl::ColorBuffer0, GL_RGBA8, GL_COLOR_ATTACHMENT0);
}

// The depth/stencil attachment(s).
#if defined (DE_HAVE_DEPTH_STENCIL_ATTACHMENT)
// The depth attachment.
if (depthStencilTex)
{
DE_ASSERT(depthStencilTex->isReady());
Expand All @@ -701,7 +712,7 @@ void GLFramebuffer::configure(const List<GLTexture *> &colorTextures,
}
else if (missingRenderBuffers & Depth)
{
d->attachRenderBuffer(Impl::DepthBuffer, GL_DEPTH24_OES, GL_DEPTH_ATTACHMENT);
d->attachRenderbuffer(Impl::DepthBuffer, GL_DEPTH_COMPONENT24_OES, GL_DEPTH_ATTACHMENT);
}

if (stencilTex)
Expand All @@ -712,7 +723,7 @@ void GLFramebuffer::configure(const List<GLTexture *> &colorTextures,
}
else if (missingRenderBuffers & Stencil)
{
d->attachRenderBuffer(Impl::StencilBuffer, GL_RED, GL_STENCIL_ATTACHMENT);
d->attachRenderbuffer(Impl::StencilBuffer, GL_STENCIL_INDEX, GL_STENCIL_ATTACHMENT);
}
#endif

Expand Down Expand Up @@ -830,11 +841,18 @@ void GLFramebuffer::clear(Flags attachments)
glClearColor(d->clearColor.x, d->clearColor.y, d->clearColor.z, d->clearColor.w);

// Only clear what we have.
Flags which = attachments & d->flags;
const Flags which = attachments & d->flags;

#if defined (DE_HAVE_COLOR_ATTACHMENTS)
glClear((which & (Color0 | Color1 | Color2 | Color3) ?
ClearBufferMask::GL_COLOR_BUFFER_BIT : ClearBufferMask::GL_NONE_BIT) |
(which & Depth ? ClearBufferMask::GL_DEPTH_BUFFER_BIT : ClearBufferMask::GL_NONE_BIT) |
(which & Stencil ? ClearBufferMask::GL_STENCIL_BUFFER_BIT : ClearBufferMask::GL_NONE_BIT));
#else
glClear((which & Color0 ? GL_COLOR_BUFFER_BIT : 0) |
(which & Depth ? GL_DEPTH_BUFFER_BIT : 0) |
(which & Stencil ? GL_STENCIL_BUFFER_BIT: 0));
#endif

// Restore previous state.
if (attachments & FullClear)
Expand Down
20 changes: 2 additions & 18 deletions doomsday/libs/gui/src/graphics/glinfo.cpp
Expand Up @@ -321,6 +321,7 @@ DE_PIMPL_NOREF(GLInfo) //, public QOpenGLFunctions_Doomsday
ext.NV_framebuffer_multisample_coverage = query("GL_NV_framebuffer_multisample_coverage");
ext.NV_texture_barrier = query("GL_NV_texture_barrier");
ext.KHR_debug = query("GL_KHR_debug");
ext.OES_rgb8_rgba8 = query("GL_OES_rgb8_rgba8");

#if defined (DE_ENABLE_OPENGL_DEBUG_LOGGER)
{
Expand Down Expand Up @@ -351,13 +352,13 @@ DE_PIMPL_NOREF(GLInfo) //, public QOpenGLFunctions_Doomsday
glGetFloatv(GL_SMOOTH_LINE_WIDTH_GRANULARITY, &lim.smoothLineWidthGranularity);
LIBGUI_ASSERT_GL_OK();
}
#endif
LIBGUI_ASSERT_GL_OK();

if (ext.EXT_texture_filter_anisotropic)
{
glGetIntegerv(gl33ext::GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &lim.maxTexFilterAniso);
}
#endif

// Set a custom maximum size?
if (CommandLine_CheckWith("-maxtex", 1))
Expand All @@ -368,23 +369,6 @@ DE_PIMPL_NOREF(GLInfo) //, public QOpenGLFunctions_Doomsday
LOG_GL_NOTE("Using requested maximum texture size of %i x %i")
<< lim.maxTexSize << lim.maxTexSize;
}

#if 0
// Check default OpenGL format attributes.
const QOpenGLContext *ctx = QOpenGLContext::currentContext();
QSurfaceFormat form = ctx->format();

LOGDEV_GL_MSG("Initial OpenGL format:");
LOGDEV_GL_MSG(" - version: %i.%i") << form.majorVersion() << form.minorVersion();
LOGDEV_GL_MSG(" - profile: %s") << (form.profile() == QSurfaceFormat::CompatibilityProfile? "Compatibility" : "Core");
LOGDEV_GL_MSG(" - color: R%i G%i B%i A%i bits") << form.redBufferSize() << form.greenBufferSize() << form.blueBufferSize() << form.alphaBufferSize();
LOGDEV_GL_MSG(" - depth: %i bits") << form.depthBufferSize();
LOGDEV_GL_MSG(" - stencil: %i bits") << form.stencilBufferSize();
LOGDEV_GL_MSG(" - samples: %i") << form.samples();
LOGDEV_GL_MSG(" - swap behavior: %i") << form.swapBehavior();

LIBGUI_ASSERT_GL_OK();
#endif
}
};

Expand Down
10 changes: 7 additions & 3 deletions doomsday/libs/gui/src/graphics/glshader.cpp
Expand Up @@ -29,7 +29,6 @@ DE_PIMPL(GLShader)
{
GLuint name = 0;
Type type = Vertex;
//Block compiledSource;

Impl(Public *i) : Base(i)
{}
Expand All @@ -44,9 +43,14 @@ DE_PIMPL(GLShader)
LIBGUI_ASSERT_GL_CONTEXT_ACTIVE();
if (!name)
{
#if defined (DE_OPENGL)
name = glCreateShader(type == Vertex ? GL_VERTEX_SHADER
: type == Geometry ? GL_GEOMETRY_SHADER
: GL_FRAGMENT_SHADER);
: type == Geometry ? GL_GEOMETRY_SHADER
: GL_FRAGMENT_SHADER);
#elif defined (DE_OPENGL_ES)
DE_ASSERT(type != Geometry);
name = glCreateShader(type == Vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
#endif
LIBGUI_ASSERT_GL_OK();
if (!name)
{
Expand Down
15 changes: 15 additions & 0 deletions doomsday/libs/gui/src/graphics/gltimer.cpp
Expand Up @@ -24,6 +24,8 @@

namespace de {

#if defined (DE_OPENGL)

DE_PIMPL_NOREF(GLTimer)
{
static const int BUF_COUNT = 2;
Expand Down Expand Up @@ -142,4 +144,17 @@ TimeSpan GLTimer::elapsedTime(const Id &id) const
return 0.0;
}

#endif // DE_OPENGL

#if defined (DE_OPENGL_ES)

// dummy implementation
DE_PIMPL_NOREF(GLTimer) {};
GLTimer::GLTimer() : d(new Impl) {}
void GLTimer::beginTimer(const Id &) {}
void GLTimer::endTimer(const Id &) {}
TimeSpan GLTimer::elapsedTime(const Id &) const { return 0.0; }

#endif

} // namespace de

0 comments on commit ee23c88

Please sign in to comment.