Nux

Merge lp:~smspillaz/nux/nux.fix_1036521 into lp:nux

Proposed by Sam Spilsbury on 2012-09-19
Status: Merged
Approved by: Neil J. Patel on 2012-09-19
Approved revision: 662
Merged at revision: 663
Proposed branch: lp:~smspillaz/nux/nux.fix_1036521
Merge into: lp:nux
Diff against target: 274 lines (+168/-63)
3 files modified
Nux/WindowCompositor.cpp (+87/-63)
Nux/WindowCompositor.h (+1/-0)
tests/gtest-nux-windowcompositor.cpp (+80/-0)
To merge this branch: bzr merge lp:~smspillaz/nux/nux.fix_1036521
Reviewer Review Type Date Requested Status
Daniel van Vugt 2012-09-19 Approve on 2012-09-19
Review via email: mp+125103@code.launchpad.net

Commit message

Added a method to WindowCompositor RestoreMainFramebuffer which either restores the reference framebuffer or binds us to the backbuffer depending on what is available.

Description of the change

Added a method to WindowCompositor RestoreMainFramebuffer which either restores the reference framebuffer or binds us to the backbuffer depending on what is available. Test suite added.

To post a comment you must log in.
Daniel van Vugt (vanvugt) wrote :

I tested and approved the Nux 3.0 proposal. I assume it's the same as this... ?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/WindowCompositor.cpp'
2--- Nux/WindowCompositor.cpp 2012-09-17 09:55:43 +0000
3+++ Nux/WindowCompositor.cpp 2012-09-19 06:28:20 +0000
4@@ -2277,80 +2277,104 @@
5 reference_fbo_geometry_ = fbo_geometry;
6 }
7
8+ namespace
9+ {
10+ bool CheckExternalFramebufferStatus (GLenum binding)
11+ {
12+ bool ok = false;
13+ // Nux does some sanity checks to make sure that the FBO is in good condition.
14+ GLenum status;
15+ status = glCheckFramebufferStatusEXT(binding);
16+ CHECKGL_MSG(glCheckFramebufferStatusEXT);
17+
18+ switch(status)
19+ {
20+ case GL_FRAMEBUFFER_COMPLETE_EXT: // Everything's OK
21+ ok = true;
22+ break;
23+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
24+ nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT");
25+ ok = false;
26+ break;
27+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
28+ nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
29+ ok = false;
30+ break;
31+ // See issue(87) of http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt
32+ // case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
33+ // nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT");
34+ // ok = false;
35+ // break;
36+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
37+ nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT");
38+ ok = false;
39+ break;
40+ #ifndef NUX_OPENGLES_20
41+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
42+ nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");
43+ ok = false;
44+ break;
45+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
46+ nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
47+ ok = false;
48+ break;
49+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
50+ nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
51+ ok = false;
52+ break;
53+ #endif
54+ // case GL_FRAMEBUFFER_STATUS_ERROR_EXT:
55+ // nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_STATUS_ERROR_EXT");
56+ // ok = false;
57+ // break;
58+ case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
59+ nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_UNSUPPORTED_EXT");
60+ ok = false;
61+ break;
62+ default:
63+ nuxError("[GLFramebufferObject::IsValid] Unknown ERROR");
64+ ok = false;
65+ }
66+
67+ return ok;
68+ }
69+
70+ void SetReferenceFramebufferViewport (const nux::Geometry &reference_fbo_geometry_)
71+ {
72+ CHECKGL(glViewport(reference_fbo_geometry_.x,
73+ reference_fbo_geometry_.y,
74+ reference_fbo_geometry_.width,
75+ reference_fbo_geometry_.height));
76+ }
77+ }
78+
79 bool WindowCompositor::RestoreReferenceFramebuffer()
80 {
81+ if (!reference_fbo_)
82+ return false;
83+
84 // It is assumed that the reference fbo contains valid textures.
85 // Nux does the following:
86 // - Bind the reference fbo (reference_fbo_)
87 // - Call glDrawBuffer with GL_COLOR_ATTACHMENT0
88 // - Set the opengl viewport size (reference_fbo_geometry_)
89
90- bool ok = false;
91-
92 CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, reference_fbo_));
93 #ifndef NUX_OPENGLES_20
94 CHECKGL(glDrawBuffer(GL_COLOR_ATTACHMENT0));
95-#endif
96- CHECKGL(glViewport(reference_fbo_geometry_.x,
97- reference_fbo_geometry_.y,
98- reference_fbo_geometry_.width,
99- reference_fbo_geometry_.height));
100-
101- // Nux does some sanity checks to make sure that the FBO is in good condition.
102- GLenum status;
103- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
104- CHECKGL_MSG(glCheckFramebufferStatusEXT);
105-
106- switch(status)
107- {
108- case GL_FRAMEBUFFER_COMPLETE_EXT: // Everything's OK
109- ok = true;
110- break;
111- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
112- nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT");
113- ok = false;
114- break;
115- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
116- nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
117- ok = false;
118- break;
119- // See issue(87) of http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt
120- // case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
121- // nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT");
122- // ok = false;
123- // break;
124- case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
125- nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT");
126- ok = false;
127- break;
128-#ifndef NUX_OPENGLES_20
129- case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
130- nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");
131- ok = false;
132- break;
133- case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
134- nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
135- ok = false;
136- break;
137- case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
138- nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
139- ok = false;
140- break;
141-#endif
142- // case GL_FRAMEBUFFER_STATUS_ERROR_EXT:
143- // nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_STATUS_ERROR_EXT");
144- // ok = false;
145- // break;
146- case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
147- nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_UNSUPPORTED_EXT");
148- ok = false;
149- break;
150- default:
151- nuxError("[GLFramebufferObject::IsValid] Unknown ERROR");
152- ok = false;
153- }
154-
155- return ok;
156+ CHECKGL(glReadBuffer(GL_COLOR_ATTACHMENT0));
157+#endif
158+
159+ SetReferenceFramebufferViewport (reference_fbo_geometry_);
160+
161+ return CheckExternalFramebufferStatus (GL_FRAMEBUFFER_EXT);
162+ }
163+
164+ void WindowCompositor::RestoreMainFramebuffer()
165+ {
166+ // This is a bit inefficient as we unbind and then rebind
167+ nux::GetGraphicsDisplay()->GetGpuDevice()->DeactivateFrameBuffer ();
168+ RestoreReferenceFramebuffer ();
169 }
170
171 #ifdef NUX_GESTURES_SUPPORT
172
173=== modified file 'Nux/WindowCompositor.h'
174--- Nux/WindowCompositor.h 2012-09-17 09:55:43 +0000
175+++ Nux/WindowCompositor.h 2012-09-19 06:28:20 +0000
176@@ -215,6 +215,7 @@
177 @return True if no error was detected.
178 */
179 bool RestoreReferenceFramebuffer();
180+ void RestoreMainFramebuffer();
181
182 ObjectPtr<IOpenGLFrameBufferObject>& GetWindowFrameBufferObject()
183 {
184
185=== modified file 'tests/gtest-nux-windowcompositor.cpp'
186--- tests/gtest-nux-windowcompositor.cpp 2012-09-03 21:06:18 +0000
187+++ tests/gtest-nux-windowcompositor.cpp 2012-09-19 06:28:20 +0000
188@@ -143,6 +143,86 @@
189 boost::shared_ptr<nux::WindowThread> wnd_thread;
190 };
191
192+namespace
193+{
194+ class ReferenceFramebuffer
195+ {
196+ public:
197+
198+ ReferenceFramebuffer ()
199+ {
200+ glGenFramebuffersEXT (1, &fboName);
201+ glGenRenderbuffersEXT (1, &rbName);
202+
203+ glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, rbName);
204+ glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_RGBA8_EXT, 300, 200);
205+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fboName);
206+ glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rbName);
207+ }
208+
209+ ~ReferenceFramebuffer ()
210+ {
211+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
212+ glDeleteRenderbuffers (1, &rbName);
213+ glDeleteRenderbuffers (1, &fboName);
214+ }
215+
216+ GLuint fboName, rbName;
217+ };
218+}
219+TEST_F(TestWindowCompositor, TestRestoreReferenceFramebufferDirect)
220+{
221+ ReferenceFramebuffer reference;
222+ GLint fbBinding;
223+
224+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &fbBinding);
225+
226+ ASSERT_EQ (fbBinding, reference.fboName);
227+
228+ wnd_thread->GetWindowCompositor().SetReferenceFramebuffer(fbBinding, nux::Geometry (0, 0, 300, 200));
229+
230+ ASSERT_TRUE (wnd_thread->GetWindowCompositor().RestoreReferenceFramebuffer());
231+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &fbBinding);
232+ ASSERT_EQ (fbBinding, reference.fboName);
233+}
234+
235+TEST_F(TestWindowCompositor, TestRestoreReferenceFramebufferThroughRestoreMain)
236+{
237+ ReferenceFramebuffer reference;
238+ GLint fbBinding;
239+
240+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &fbBinding);
241+
242+ ASSERT_EQ (fbBinding, reference.fboName);
243+
244+ wnd_thread->GetWindowCompositor().SetReferenceFramebuffer(fbBinding, nux::Geometry (0, 0, 300, 200));
245+ wnd_thread->GetWindowCompositor().RestoreMainFramebuffer();
246+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &fbBinding);
247+ ASSERT_EQ (fbBinding, reference.fboName);
248+}
249+
250+TEST_F(TestWindowCompositor, TestNoRestoreReferenceFramebufferDirectIfNoReferenceFramebuffer)
251+{
252+ GLint fbBinding;
253+ ASSERT_FALSE (wnd_thread->GetWindowCompositor().RestoreReferenceFramebuffer());
254+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &fbBinding);
255+ ASSERT_EQ (fbBinding, 0);
256+}
257+
258+TEST_F(TestWindowCompositor, TestRestoreBackbufferThroughRestoreMain)
259+{
260+ ReferenceFramebuffer reference;
261+ GLint fbBinding;
262+
263+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &fbBinding);
264+
265+ ASSERT_EQ (fbBinding, reference.fboName);
266+
267+ wnd_thread->GetWindowCompositor().RestoreMainFramebuffer();
268+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &fbBinding);
269+ ASSERT_EQ (fbBinding, 0);
270+}
271+
272 TEST_F(TestWindowCompositor, TestSetKeyFocusArea)
273 {
274 nux::TestView* test_view0 = new nux::TestView();

Subscribers

People subscribed via source and target branches