author | unc0rr |
Sun, 07 Jan 2018 09:48:26 +0100 | |
branch | qmlfrontend |
changeset 12884 | 66171ce586cc |
parent 12883 | adb1fccc706a |
child 12890 | 9c259fb4d405 |
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; |
12883
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
11 |
extern ResizeWindow_t* flibResizeWindow; |
12876
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 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
14 |
GameView::GameView() |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
15 |
: 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
|
16 |
, m_renderer(0) |
12883
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
17 |
, m_windowChanged(true) |
12876
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 |
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
|
20 |
} |
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 |
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
|
23 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
24 |
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
|
25 |
if (window()) |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
26 |
window()->update(); |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
27 |
} |
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 |
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
|
30 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
31 |
if (win) { |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
35 |
win->setClearBeforeRendering(false); |
12883
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
36 |
|
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
37 |
m_windowChanged = true; |
12876
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 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
40 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
41 |
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
|
42 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
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
|
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 |
} |
12883
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
55 |
|
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
56 |
if (m_windowChanged) |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
57 |
m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio()); |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
58 |
|
12876
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
59 |
m_renderer->tick(m_delta); |
12883
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
60 |
} |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
61 |
|
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
62 |
GameViewRenderer::~GameViewRenderer() |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
63 |
{ |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
64 |
} |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
65 |
|
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
66 |
void GameViewRenderer::setViewportSize(const QSize& size) |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
67 |
{ |
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
68 |
flibResizeWindow(size.width(), size.height()); |
12876
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
69 |
} |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
70 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
71 |
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
|
72 |
{ |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
73 |
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
|
74 |
return; |
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
75 |
|
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
76 |
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
|
77 |
|
12883
adb1fccc706a
- ResizeWindow function to pass engine new window size
unc0rr
parents:
12876
diff
changeset
|
78 |
//m_window->resetOpenGLState(); |
12876
b544bbbd0696
Break engine completely and make it render in frontend window (no actual rendering yet, just white screen)
unc0rr
parents:
diff
changeset
|
79 |
} |