Skip to content

Commit

Permalink
Refactor|Cleanup|libgui: Cleaning up Canvas/CanvasWindow and window i…
Browse files Browse the repository at this point in the history
…nit/drawing

Cutting down on the cruft. The Qt 5 OpenGL APIs allow for a cleaner
implementation of window initialization and refresh. The "frame
swapped" signal is particularly helpful.

Using an audience for drawing the window contents is not the best
idea because the order of audience callbacks is unspecified. Now
the draw() method is a simple virtual method call back to the parent
CanvasWindow.

GLInfo now checks for the EXT_timer_query extension.
  • Loading branch information
skyjake committed Sep 6, 2016
1 parent b1baae6 commit cbe655c
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 436 deletions.
1 change: 1 addition & 0 deletions doomsday/sdk/libgui/include/de/graphics/glinfo.h
Expand Up @@ -62,6 +62,7 @@ class LIBGUI_PUBLIC GLInfo
duint32 EXT_packed_depth_stencil : 1;
duint32 EXT_texture_compression_s3tc : 1;
duint32 EXT_texture_filter_anisotropic : 1;
duint32 EXT_timer_query : 1;

// Vendor-specific extensions:
duint32 ATI_texture_env_combine3 : 1;
Expand Down
62 changes: 11 additions & 51 deletions doomsday/sdk/libgui/include/de/gui/canvas.h
@@ -1,6 +1,6 @@
/** @file canvas.h OpenGL drawing surface (QWidget).
*
* @authors Copyright (c) 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright (c) 2012-2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
Expand Down Expand Up @@ -35,8 +35,9 @@ class CanvasWindow;

/**
* Drawing canvas with an OpenGL context and window surface. Each CanvasWindow
* creates one Canvas instance on which to draw. Buffer swapping must be done
* manually when appropriate.
* creates one Canvas instance on which to draw. Buffer swapping occurs automatically
* after the canvas has been painted. The GLSwapped audience is notified whenever a
* swap is completed.
*
* As Canvas is derived from KeyEventSource and MouseEventSource so that it
* can submit user input to interested parties.
Expand All @@ -51,17 +52,9 @@ class LIBGUI_PUBLIC Canvas : public QOpenGLWidget, public KeyEventSource, public
typedef Vector2ui Size;

/**
* Notified when the canvas is ready for GL operations. The OpenGL context
* and drawing surface are not ready to be used before that. The
* notification occurs soon after the widget first becomes visible on
* screen. Note that the notification comes straight from the event loop
* (timer signal) instead of during a paint event.
*/
DENG2_DEFINE_AUDIENCE2(GLReady, void canvasGLReady(Canvas &))

/**
* Notified when the canvas's GL state needs to be initialized. This is
* called immediately before drawing the contents of the canvas for the
* Notified when the canvas's GL state needs to be initialized. The OpenGL
* context and drawing surface are not ready before this occurs. This gets
* called immediately before drawing the contents of the Canvas for the
* first time (during a paint event).
*/
DENG2_DEFINE_AUDIENCE2(GLInit, void canvasGLInit(Canvas &))
Expand All @@ -72,9 +65,10 @@ class LIBGUI_PUBLIC Canvas : public QOpenGLWidget, public KeyEventSource, public
DENG2_DEFINE_AUDIENCE2(GLResize, void canvasGLResized(Canvas &))

/**
* Notified when drawing of the canvas contents has been requested.
* Notified when the contents of the canvas have been swapped to the window front
* buffer and are thus visible to the user.
*/
DENG2_DEFINE_AUDIENCE2(GLDraw, void canvasGLDraw(Canvas &))
DENG2_DEFINE_AUDIENCE2(GLSwapped, void canvasGLSwapped(Canvas &))

/**
* Notified when the canvas gains or loses input focus.
Expand All @@ -84,13 +78,6 @@ class LIBGUI_PUBLIC Canvas : public QOpenGLWidget, public KeyEventSource, public
public:
explicit Canvas(CanvasWindow *parent);

/**
* Sets or changes the CanvasWindow that owns this Canvas.
*
* @param parent Canvas window instance.
*/
void setParent(CanvasWindow *parent);

/**
* Grabs the contents of the canvas framebuffer.
*
Expand All @@ -112,19 +99,6 @@ class LIBGUI_PUBLIC Canvas : public QOpenGLWidget, public KeyEventSource, public
*/
QImage grabImage(QRect const &area, QSize const &outputSize = QSize());

/**
* Grabs the contents of the canvas framebuffer and creates an OpenGL
* texture out of it.
*
* @param outputSize If specified, the contents will be scaled to this size before
* the image is returned.
*
* @return OpenGL texture name. Caller is responsible for deleting the texture.
*/
//GLuint grabAsTexture(QSize const &outputSize = QSize());

//GLuint grabAsTexture(QRect const &area, QSize const &outputSize = QSize());

/**
* Returns the size of the canvas in device pixels.
*/
Expand Down Expand Up @@ -155,26 +129,13 @@ class LIBGUI_PUBLIC Canvas : public QOpenGLWidget, public KeyEventSource, public

bool isGLReady() const;

/**
* Replaces the current audiences of this canvas with another canvas's
* audiences.
*
* @param other Canvas instance.
*/
void copyAudiencesFrom(Canvas const &other);

/**
* Returns a render target that renders to this canvas.
*
* @return GL render target.
*/
GLTextureFramebuffer &framebuffer() const;

/**
* Copies or swaps the back buffer to the front, making it visible.
*/
//void swapBuffers(gl::SwapBufferMode swapMode = gl::SwapMonoBuffer);

protected:
void initializeGL();
void resizeGL(int w, int h);
Expand All @@ -190,11 +151,10 @@ class LIBGUI_PUBLIC Canvas : public QOpenGLWidget, public KeyEventSource, public
void mouseDoubleClickEvent(QMouseEvent *ev);
void mouseMoveEvent(QMouseEvent *ev);
void wheelEvent(QWheelEvent *ev);
//void showEvent(QShowEvent *ev);

protected slots:
void notifyReady();
void updateSize();
void frameWasSwapped();

private:
DENG2_PRIVATE(d)
Expand Down
49 changes: 3 additions & 46 deletions doomsday/sdk/libgui/include/de/gui/canvaswindow.h
@@ -1,6 +1,6 @@
/** @file canvaswindow.h Top-level window with a Canvas.
*
* @authors Copyright © 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2012-2016 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
*
* @par License
Expand Down Expand Up @@ -47,9 +47,7 @@ namespace de {
*
* @see Canvas
*/
class LIBGUI_PUBLIC CanvasWindow : public QMainWindow,
DENG2_OBSERVES(Canvas, GLReady),
DENG2_OBSERVES(Canvas, GLDraw)
class LIBGUI_PUBLIC CanvasWindow : public QMainWindow, public Asset
{
Q_OBJECT

Expand All @@ -61,11 +59,6 @@ class LIBGUI_PUBLIC CanvasWindow : public QMainWindow,
public:
CanvasWindow();

/**
* Determines if the canvas is ready for GL drawing.
*/
bool isReady() const;

float frameRate() const;

/**
Expand All @@ -85,12 +78,6 @@ class LIBGUI_PUBLIC CanvasWindow : public QMainWindow,
*/
inline int height() const { return canvas().height(); }

/**
* Recreates the contained Canvas with an updated GL format. The context is
* shared with the old Canvas.
*/
//void recreateCanvas();

Canvas& canvas() const;

/**
Expand All @@ -108,37 +95,12 @@ class LIBGUI_PUBLIC CanvasWindow : public QMainWindow,
#endif
void hideEvent(QHideEvent *);

/**
* Called when the Canvas is ready for OpenGL drawing (and visible).
* Overriding methods must call this.
*
* @param canvas Canvas.
*/
virtual void canvasGLReady(Canvas &canvas);

/**
* Called from Canvas when a GL draw is requested. Overriding methods
* must call this as the last operation (updates frame rate statistics).
*/
virtual void canvasGLDraw(Canvas &);

enum GrabMode
{
GrabNormal,
GrabHalfSized
};

/**
* Grab the contents of the window into an OpenGL texture.
*
* @param grabMode How to do the grabbing.
*
* @return OpenGL texture name. Caller is reponsible for deleting the texture.
*/
//duint grabAsTexture(GrabMode grabMode = GrabNormal) const;

//duint grabAsTexture(de::Rectanglei const &area, GrabMode mode = GrabNormal) const;

/**
* Grabs the contents of the window and saves it into a native image file.
*
Expand All @@ -150,8 +112,6 @@ class LIBGUI_PUBLIC CanvasWindow : public QMainWindow,
*/
bool grabToFile(NativePath const &path) const;

//void swapBuffers(gl::SwapBufferMode swapMode = gl::SwapMonoBuffer) const;

/**
* Activates the window's GL context so that OpenGL API calls can be made.
* The GL context is automatically active during the drawing of the window's
Expand All @@ -171,10 +131,7 @@ class LIBGUI_PUBLIC CanvasWindow : public QMainWindow,
*/
void *nativeHandle() const;

//bool isRecreationInProgress() const;

protected slots:
//void finishCanvasRecreation();
virtual void draw();

public:
static bool mainExists();
Expand Down

0 comments on commit cbe655c

Please sign in to comment.