diff --git a/doomsday/libs/gui/include/de/graphics/glinfo.h b/doomsday/libs/gui/include/de/graphics/glinfo.h index 4e0413349c..300f4f4d7f 100644 --- a/doomsday/libs/gui/include/de/graphics/glinfo.h +++ b/doomsday/libs/gui/include/de/graphics/glinfo.h @@ -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; diff --git a/doomsday/libs/gui/include/de/graphics/gltimer.h b/doomsday/libs/gui/include/de/graphics/gltimer.h index ff97593e9f..ea72151f16 100644 --- a/doomsday/libs/gui/include/de/graphics/gltimer.h +++ b/doomsday/libs/gui/include/de/graphics/gltimer.h @@ -16,8 +16,7 @@ * http://www.gnu.org/licenses */ -#ifndef LIBGUI_GLTIMER_H -#define LIBGUI_GLTIMER_H +#pragma once #include #include "de/libgui.h" @@ -72,5 +71,3 @@ class LIBGUI_PUBLIC GLTimer }; } // namespace de - -#endif // LIBGUI_GLTIMER_H diff --git a/doomsday/libs/gui/include/de/graphics/opengl.h b/doomsday/libs/gui/include/de/graphics/opengl.h index 773f066f9b..8ae18818b1 100644 --- a/doomsday/libs/gui/include/de/graphics/opengl.h +++ b/doomsday/libs/gui/include/de/graphics/opengl.h @@ -39,6 +39,7 @@ using namespace gl33core; #elif (DE_OPENGL_ES == 20) # include +# include #endif // Defined in GLES2. diff --git a/doomsday/libs/gui/src/graphics/glframebuffer.cpp b/doomsday/libs/gui/src/graphics/glframebuffer.cpp index 5f9e731abb..78a0b246db 100644 --- a/doomsday/libs/gui/src/graphics/glframebuffer.cpp +++ b/doomsday/libs/gui/src/graphics/glframebuffer.cpp @@ -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) { @@ -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 { @@ -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) @@ -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); } @@ -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)) { @@ -367,6 +379,7 @@ 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)) @@ -374,16 +387,13 @@ DE_PIMPL(GLFramebuffer) 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() { @@ -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() @@ -512,9 +525,7 @@ DE_PIMPL(GLFramebuffer) } DE_ASSERT(fbo != 0); - - //glBindFramebuffer(GL_FRAMEBUFFER, fbo); - + glBind(); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); @@ -679,8 +690,8 @@ void GLFramebuffer::configure(const List &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()); @@ -701,7 +712,7 @@ void GLFramebuffer::configure(const List &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) @@ -712,7 +723,7 @@ void GLFramebuffer::configure(const List &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 @@ -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) diff --git a/doomsday/libs/gui/src/graphics/glinfo.cpp b/doomsday/libs/gui/src/graphics/glinfo.cpp index e0e2060b48..63f55ef3d7 100644 --- a/doomsday/libs/gui/src/graphics/glinfo.cpp +++ b/doomsday/libs/gui/src/graphics/glinfo.cpp @@ -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) { @@ -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)) @@ -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 } }; diff --git a/doomsday/libs/gui/src/graphics/glshader.cpp b/doomsday/libs/gui/src/graphics/glshader.cpp index c858c3272c..360f1f8525 100644 --- a/doomsday/libs/gui/src/graphics/glshader.cpp +++ b/doomsday/libs/gui/src/graphics/glshader.cpp @@ -29,7 +29,6 @@ DE_PIMPL(GLShader) { GLuint name = 0; Type type = Vertex; - //Block compiledSource; Impl(Public *i) : Base(i) {} @@ -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) { diff --git a/doomsday/libs/gui/src/graphics/gltimer.cpp b/doomsday/libs/gui/src/graphics/gltimer.cpp index 8dac16a3dd..5f5a20fff7 100644 --- a/doomsday/libs/gui/src/graphics/gltimer.cpp +++ b/doomsday/libs/gui/src/graphics/gltimer.cpp @@ -24,6 +24,8 @@ namespace de { +#if defined (DE_OPENGL) + DE_PIMPL_NOREF(GLTimer) { static const int BUF_COUNT = 2; @@ -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