author | unc0rr |
Fri, 05 Jan 2018 22:32:11 +0100 | |
branch | qmlfrontend |
changeset 12880 | 590c7f324292 |
parent 12876 | b544bbbd0696 |
child 12883 | adb1fccc706a |
permissions | -rw-r--r-- |
12876
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
1 |
#include "gameview.h" |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
2 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
3 |
#include <QtGui/QOpenGLContext> |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
4 |
#include <QtGui/QOpenGLShaderProgram> |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
5 |
#include <QtQuick/qquickwindow.h> |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
6 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
7 |
#include "flib.h" |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
8 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
9 |
extern "C" { |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
10 |
extern GameTick_t* flibGameTick; |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
11 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
12 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
13 |
GameView::GameView() |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
14 |
: m_delta(0) |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
15 |
, m_renderer(0) |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
16 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
17 |
connect(this, &QQuickItem::windowChanged, this, &GameView::handleWindowChanged); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
18 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
19 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
20 |
void GameView::tick(quint32 delta) |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
21 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
22 |
m_delta = delta; |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
23 |
if (window()) |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
24 |
window()->update(); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
25 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
26 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
27 |
void GameView::handleWindowChanged(QQuickWindow* win) |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
28 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
29 |
if (win) { |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
30 |
connect(win, &QQuickWindow::beforeSynchronizing, this, &GameView::sync, Qt::DirectConnection); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
31 |
connect(win, &QQuickWindow::sceneGraphInvalidated, this, &GameView::cleanup, Qt::DirectConnection); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
32 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
33 |
win->setClearBeforeRendering(false); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
34 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
35 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
36 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
37 |
void GameView::cleanup() |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
38 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
39 |
if (m_renderer) { |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
40 |
delete m_renderer; |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
41 |
m_renderer = 0; |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
42 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
43 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
44 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
45 |
GameViewRenderer::~GameViewRenderer() |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
46 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
47 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
48 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
49 |
void GameView::sync() |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
50 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
51 |
if (!m_renderer) { |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
52 |
m_renderer = new GameViewRenderer(); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
53 |
connect(window(), &QQuickWindow::beforeRendering, m_renderer, &GameViewRenderer::paint, Qt::DirectConnection); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
54 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
55 |
m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio()); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
56 |
m_renderer->tick(m_delta); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
57 |
m_renderer->setWindow(window()); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
58 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
59 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
60 |
void GameViewRenderer::paint() |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
61 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
62 |
if (m_delta == 0) |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
63 |
return; |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
64 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
65 |
flibGameTick(m_delta); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
66 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
67 |
m_window->resetOpenGLState(); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
68 |
} |