Skip to content

Commit

Permalink
Refactor|libappfw|Tests: Updated for new GL classes (work in progress)
Browse files Browse the repository at this point in the history
Use of the GLTarget/GLFramebuffer classes was revised.

The old GL buffer swapping mechanism was removed, because the new
QOpenGL* classes handle swapping to the final window surface.

Our GL code is only responsible for drawing the contents of the window
into the FBO provided by Qt.

Test apps were updated with relevant changes, and a fix for macOS
bundle deployment (Doomsday libraries were not being installed).
  • Loading branch information
skyjake committed Sep 4, 2016
1 parent fbd925e commit 7b21c6b
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 97 deletions.
25 changes: 0 additions & 25 deletions doomsday/cmake/OpenGL.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions doomsday/sdk/libappfw/CMakeLists.txt
Expand Up @@ -9,7 +9,6 @@ find_package (DengCore)
find_package (DengGui)
find_package (DengShell)
find_package (OculusVR QUIET)
include (OpenGL)

# Definitions.
add_definitions (-D__LIBAPPFW__=1)
Expand All @@ -27,7 +26,6 @@ deng_add_library (libappfw ${SOURCES} ${HEADERS})

target_link_libraries (libappfw
PUBLIC Deng::libcore Deng::libgui Deng::libshell
PRIVATE opengl
)
deng_target_link_qt (libappfw PUBLIC Widgets OpenGL)
if (TARGET LibOVR)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libappfw/include/de/framework/baseguiapp.h
Expand Up @@ -47,6 +47,8 @@ class LIBAPPFW_PUBLIC BaseGuiApp : public GuiApp
public:
BaseGuiApp(int &argc, char **argv);

virtual void glDeinit();

void initSubsystems(SubsystemInitFlags flags = DefaultSubsystems);
double dpiFactor() const;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/include/de/framework/basewindow.h
Expand Up @@ -85,7 +85,7 @@ class LIBAPPFW_PUBLIC BaseWindow : public PersistentCanvasWindow

void canvasGLDraw(Canvas &);

void swapBuffers();
//void swapBuffers();

protected:
/**
Expand Down
Expand Up @@ -25,7 +25,7 @@

namespace de {

class GLFramebuffer;
class GLTextureFramebuffer;

/**
* Window content transformation for virtual reality.
Expand All @@ -45,7 +45,7 @@ class LIBAPPFW_PUBLIC VRWindowTransform : public WindowTransform

void drawTransformed();

GLFramebuffer &unwarpedFramebuffer();
GLTextureFramebuffer &unwarpedFramebuffer();

private:
DENG2_PRIVATE(d)
Expand Down
6 changes: 6 additions & 0 deletions doomsday/sdk/libappfw/src/baseguiapp.cpp
Expand Up @@ -130,6 +130,12 @@ BaseGuiApp::BaseGuiApp(int &argc, char **argv)
<< DENG2_FUNC (App_LoadFont, "loadFont", "fileName");
}

void BaseGuiApp::glDeinit()
{
d->vr.oculusRift().deinit();
d->shaders.clear();
}

double BaseGuiApp::dpiFactor() const
{
return d->dpiFactor;
Expand Down
10 changes: 5 additions & 5 deletions doomsday/sdk/libappfw/src/basewindow.cpp
Expand Up @@ -137,15 +137,15 @@ void BaseWindow::draw()
vr.oculusRift().deinit();
}

if (shouldRepaintManually())
/*if (shouldRepaintManually())
{
DENG2_ASSERT_IN_MAIN_THREAD();
// Perform the drawing manually right away.
canvas().makeCurrent();
canvas().updateGL();
}
else
else*/
{
// Request update at the earliest convenience.
canvas().update();
Expand All @@ -161,13 +161,13 @@ void BaseWindow::canvasGLDraw(Canvas &cv)
PersistentCanvasWindow::canvasGLDraw(cv);
}

void BaseWindow::swapBuffers()
/*void BaseWindow::swapBuffers()
{
DENG2_ASSERT(DENG2_BASE_GUI_APP->vr().mode() != VRConfig::OculusRift);
PersistentCanvasWindow::swapBuffers(DENG2_BASE_GUI_APP->vr().needsStereoGLFormat()?
gl::SwapStereoBuffers : gl::SwapMonoBuffer);
}
}*/

void BaseWindow::preDraw()
{
Expand All @@ -189,7 +189,7 @@ void BaseWindow::postDraw()
// The timer loop was paused when the frame was requested to be drawn.
DENG2_GUI_APP->loop().resume();

//qDebug() << "Draw count:" << GLBuffer::drawCount();
qDebug() << "Draw count:" << GLBuffer::drawCount();
}

} // namespace de
4 changes: 2 additions & 2 deletions doomsday/sdk/libappfw/src/guirootwidget.cpp
Expand Up @@ -26,7 +26,7 @@
#include <de/CanvasWindow>
#include <de/TextureBank>
#include <de/GLUniform>
#include <de/GLTarget>
#include <de/GLFramebuffer>
#include <de/GLState>

#include <QImage>
Expand Down Expand Up @@ -413,7 +413,7 @@ void GuiRootWidget::draw()
{
// Widgets may not yet be ready on the first frame; make sure
// we don't show garbage.
window().canvas().renderTarget().clear(GLTarget::Color);
window().canvas().renderTarget().clear(GLFramebuffer::Color);

d->noFramesDrawnYet = false;
}
Expand Down
12 changes: 6 additions & 6 deletions doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -27,7 +27,7 @@
#include <de/MouseEvent>
#include <de/Drawable>
#include <de/GLTexture>
#include <de/GLTarget>
#include <de/GLTextureFramebuffer>
#include <de/FocusWidget>
#include <de/PopupWidget>

Expand Down Expand Up @@ -64,7 +64,7 @@ DENG2_PIMPL(GuiWidget)
struct BlurState
{
Vector2ui size;
QScopedPointer<GLFramebuffer> fb[2];
QScopedPointer<GLTextureFramebuffer> fb[2];
Drawable drawable;
GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 };
GLUniform uColor { "uColor", GLUniform::Vec4 };
Expand Down Expand Up @@ -184,7 +184,7 @@ DENG2_PIMPL(GuiWidget)
for (int i = 0; i < 2; ++i)
{
// Multisampling is disabled in the blurs for now.
blur->fb[i].reset(new GLFramebuffer(Image::RGB_888, blur->size, 1));
blur->fb[i].reset(new GLTextureFramebuffer(Image::RGB_888, blur->size, 1));
blur->fb[i]->glInit();
blur->fb[i]->colorTexture().setFilter(gl::Linear, gl::Linear, gl::MipNone);
}
Expand Down Expand Up @@ -269,16 +269,16 @@ DENG2_PIMPL(GuiWidget)
// Pass 1: render all the widgets behind this one onto the first blur
// texture, downsampled.
GLState::push()
.setTarget(blur->fb[0]->target())
.setTarget(*blur->fb[0])
.setViewport(Rectangleui::fromSize(blur->size));
blur->fb[0]->target().clear(GLTarget::Depth);
blur->fb[0]->clear(GLFramebuffer::Depth);
self.root().drawUntil(self);
GLState::pop();

// Pass 2: apply the horizontal blur filter to draw the background
// contents onto the second blur texture.
GLState::push()
.setTarget(blur->fb[1]->target())
.setTarget(*blur->fb[1])
.setViewport(Rectangleui::fromSize(blur->size));
blur->uTex = blur->fb[0]->colorTexture();
blur->uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1);
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libappfw/src/vr/oculusrift.cpp
Expand Up @@ -21,7 +21,7 @@
#include "de/BaseWindow"
#include "de/VRWindowTransform"

#include <de/GLFramebuffer>
#include <de/GLTextureFramebuffer>
#include <de/GLState>
#include <de/Lockable>
#include <de/Guard>
Expand Down Expand Up @@ -135,7 +135,7 @@ DENG2_PIMPL(OculusRift)
#ifdef DENG_HAVE_OCULUS_API
/// Returns the offscreen framebuffer where the Oculus Rift raw frame is drawn.
/// This is passed to LibOVR as a texture.
GLFramebuffer &framebuffer()
GLTextureFramebuffer &framebuffer()
{
DENG2_ASSERT(window);
return window->transform().as<VRWindowTransform>().unwarpedFramebuffer();
Expand Down Expand Up @@ -177,7 +177,7 @@ DENG2_PIMPL(OculusRift)

LOGDEV_GL_MSG("Clip FOV: %.2f degrees") << fovXDegrees;

framebuffer().resize(GLFramebuffer::Size(size[0].w + size[1].w,
framebuffer().resize(GLTextureFramebuffer::Size(size[0].w + size[1].w,
max(size[0].h, size[1].h)));
uint const w = framebuffer().size().x;
uint const h = framebuffer().size().y;
Expand Down
27 changes: 14 additions & 13 deletions doomsday/sdk/libappfw/src/vrwindowtransform.cpp
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/VRWindowTransform"
Expand All @@ -24,15 +24,16 @@
#include "de/GuiWidget"

#include <de/Drawable>
#include <de/GLFramebuffer>
#include <de/GLInfo>
#include <de/GLTextureFramebuffer>

namespace de {

DENG2_PIMPL(VRWindowTransform)
{
VRConfig &vrCfg;

GLFramebuffer unwarpedFB;
GLTextureFramebuffer unwarpedFB;

Impl(Public *i)
: Base(i)
Expand All @@ -49,7 +50,7 @@ DENG2_PIMPL(VRWindowTransform)
return self.window().canvas();
}

GLTarget &target() const
GLFramebuffer &target() const
{
return canvas().renderTarget();
}
Expand Down Expand Up @@ -101,12 +102,12 @@ DENG2_PIMPL(VRWindowTransform)

// Set render target to offscreen temporarily.
GLState::push()
.setTarget(unwarpedFB.target())
.setTarget(unwarpedFB)
.setViewport(Rectangleui::fromSize(unwarpedFB.size()))
.apply();
unwarpedFB.target().unsetActiveRect(true);
unwarpedFB.unsetActiveRect(true);

GLFramebuffer::Size const fbSize = unwarpedFB.size();
GLTextureFramebuffer::Size const fbSize = unwarpedFB.size();

// Left eye view on left side of screen.
for (int eyeIdx = 0; eyeIdx < 2; ++eyeIdx)
Expand All @@ -115,17 +116,17 @@ DENG2_PIMPL(VRWindowTransform)
if (ovr.currentEye() == OculusRift::LeftEye)
{
// Left eye on the left side of the screen.
unwarpedFB.target().setActiveRect(Rectangleui(0, 0, fbSize.x/2, fbSize.y), true);
unwarpedFB.setActiveRect(Rectangleui(0, 0, fbSize.x/2, fbSize.y), true);
}
else
{
// Right eye on the right side of screen.
unwarpedFB.target().setActiveRect(Rectangleui(fbSize.x/2, 0, fbSize.x/2, fbSize.y), true);
unwarpedFB.setActiveRect(Rectangleui(fbSize.x/2, 0, fbSize.x/2, fbSize.y), true);
}
drawContent();
}

unwarpedFB.target().unsetActiveRect(true);
unwarpedFB.unsetActiveRect(true);
GLState::pop().apply();

vrCfg.enableFrustumShift(); // restore default
Expand Down Expand Up @@ -233,12 +234,12 @@ DENG2_PIMPL(VRWindowTransform)
// Left eye view
vrCfg.setCurrentEye(VRConfig::LeftEye);
drawContent();
canvas().framebuffer().swapBuffers(canvas(), gl::SwapStereoLeftBuffer);
//canvas().framebuffer().swapBuffers(canvas(), gl::SwapStereoLeftBuffer);

// Right eye view
vrCfg.setCurrentEye(VRConfig::RightEye);
drawContent();
canvas().framebuffer().swapBuffers(canvas(), gl::SwapStereoRightBuffer);
//canvas().framebuffer().swapBuffers(canvas(), gl::SwapStereoRightBuffer);
}
else
{
Expand Down Expand Up @@ -379,7 +380,7 @@ void VRWindowTransform::drawTransformed()
d->draw();
}

GLFramebuffer &VRWindowTransform::unwarpedFramebuffer()
GLTextureFramebuffer &VRWindowTransform::unwarpedFramebuffer()
{
return d->unwarpedFB;
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/sdk/libappfw/src/widgets/compositorwidget.cpp
Expand Up @@ -27,7 +27,7 @@ DENG_GUI_PIMPL(CompositorWidget)
Drawable drawable;
struct Buffer {
GLTexture texture;
QScopedPointer<GLTarget> offscreen;
QScopedPointer<GLFramebuffer> offscreen;

void clear() {
texture.clear();
Expand Down Expand Up @@ -68,7 +68,7 @@ DENG_GUI_PIMPL(CompositorWidget)
{
//qDebug() << "buffer texture defined" << size.asText();
buf->texture.setUndefinedImage(size, Image::RGBA_8888);
buf->offscreen.reset(new GLTarget(buf->texture));
buf->offscreen.reset(new GLFramebuffer(buf->texture));
}
nextBufIndex++;
return buf;
Expand Down Expand Up @@ -149,7 +149,7 @@ void CompositorWidget::preDrawChildren()
.setTarget(*buf->offscreen)
.setViewport(Rectangleui::fromSize(buf->texture.size()));

buf->offscreen->clear(GLTarget::Color);
buf->offscreen->clear(GLFramebuffer::Color);
}

void CompositorWidget::postDrawChildren()
Expand Down Expand Up @@ -182,7 +182,7 @@ void CompositorWidget::drawComposite()
{
if (!d->shouldBeDrawn()) return;

glEnable(GL_TEXTURE_2D);
//LIBGUI_GL.glEnable(GL_TEXTURE_2D);

DENG2_ASSERT(d->nextBufIndex > 0);

Expand Down
9 changes: 6 additions & 3 deletions doomsday/tests/test_appfw/CMakeLists.txt
Expand Up @@ -2,17 +2,20 @@ cmake_minimum_required (VERSION 3.1)
project (DENG_TEST_APPFW)
include (../TestConfig.cmake)

find_package (Qt5 COMPONENTS Gui OpenGL Widgets)
find_package (Qt5 COMPONENTS Gui Widgets)
find_package (DengAppfw)
include (OpenGL)

deng_add_package (net.dengine.test.appfw)

file (GLOB SOURCES src/*.cpp src/*.h)
deng_add_application (test_appfw ${SOURCES})

target_link_libraries (test_appfw Deng::libappfw opengl)
target_link_libraries (test_appfw Deng::libappfw)

if (APPLE)
set_property (TARGET test_appfw PROPERTY OUTPUT_NAME test_appfw)
deng_install_bundle_deps (test_appfw
Deng::libcore Deng::libgui Deng::libappfw Deng::libshell
)
deng_install_deployqt (test_appfw)
endif ()

0 comments on commit 7b21c6b

Please sign in to comment.