annotate edview.cpp @ 391:28a74940f2b6

More work on the editor.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 19 Oct 2012 04:30:24 +0300
parents eb5b793c8867
children 8660c6005032
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "edview.h"
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
2 #include <QtGui>
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
5 GLDemoView::GLDemoView(QWidget *parent) :
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
6 QGLWidget(QGLFormat(QGL::SampleBuffers|QGL::AlphaChannel), parent)
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 {
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 makeCurrent();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 if (QGLFramebufferObject::hasOpenGLFramebufferBlit())
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 {
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 QGLFramebufferObjectFormat format;
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 format.setSamples(4);
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
16 // render_fbo = new QGLFramebufferObject(512, 512, format);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
17 // texture_fbo = new QGLFramebufferObject(512, 512);
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 }
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 else
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
21 // render_fbo = new QGLFramebufferObject(1024, 1024);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
22 // texture_fbo = render_fbo;
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 }
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 }
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
26
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
27 GLDemoView::~GLDemoView()
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 {
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
29 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
30
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
31
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
32 void GLDemoView::setEngineData(DMEngineData *mengine)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
33 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
34 engine = mengine;
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 }
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
38 void GLDemoView::render(int frameTime)
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
40 if (engine != NULL)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
41 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
42 engine->frameTime = frameTime;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
43
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
44 if (engine->demoRender != NULL)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
45 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
46 engine->demoRender(engine);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
47 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
48 else
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
49 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
50 dmExecuteTimeline(engine->ptl, engine->screen, engineGetTick(engine));
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
51 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
52
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
53 engine->frameCount++;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
54 }
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 }
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
58 void GLDemoView::paintEvent(QPaintEvent *)
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 {
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 // save the GL state set for QPainter
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 saveGLState();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 // restore the GL state that QPainter expects
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 restoreGLState();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 }
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
68 void GLDemoView::saveGLState()
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 {
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 glPushAttrib(GL_ALL_ATTRIB_BITS);
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 glMatrixMode(GL_PROJECTION);
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 glPushMatrix();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 glMatrixMode(GL_MODELVIEW);
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 glPushMatrix();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
78 void GLDemoView::restoreGLState()
385
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 {
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 glMatrixMode(GL_PROJECTION);
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 glPopMatrix();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 glMatrixMode(GL_MODELVIEW);
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 glPopMatrix();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 glPopAttrib();
eb5b793c8867 GL display widget skeleton.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 }
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
86
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
87
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
88 SWDemoView::SWDemoView(QWidget *parent) : GLDemoView(parent)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
89 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
90 img = NULL;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
91 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
92
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
93
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
94 SWDemoView::~SWDemoView()
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
95 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
96 delete img;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
97 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
98
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
99
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
100 void SWDemoView::setEngineData(DMEngineData *mengine)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
101 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
102 engine = mengine;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
103 delete img;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
104
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
105 img = new QImage((const uchar *)mengine->screen->pixels,
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
106 mengine->screen->w, mengine->screen->h,
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
107 mengine->screen->pitch, QImage::Format_RGB32);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
108 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
109
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
110
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
111 void SWDemoView::paintEvent(QPaintEvent *)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
112 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
113 if (img != NULL)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
114 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
115 QPainter painter(this);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
116 painter.drawImage(QPoint(0, 0), *img);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
117 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
118 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
119
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
120
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
121 void SWDemoView::render(int frameTime)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
122 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
123 if (SDL_MUSTLOCK(engine->screen) != 0 && SDL_LockSurface(engine->screen) != 0)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
124 return;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
125
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
126 GLDemoView::render(frameTime);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
127
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
128 if (SDL_MUSTLOCK(engine->screen) != 0)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
129 SDL_UnlockSurface(engine->screen);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
130
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
131 update();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
132 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
133
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
134