Merge lp:~linaro-graphics-wg/glmark2/desktop into lp:glmark2/2011.11
- desktop
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 130 |
Proposed branch: | lp:~linaro-graphics-wg/glmark2/desktop |
Merge into: | lp:glmark2/2011.11 |
Diff against target: |
958 lines (+848/-8) 9 files modified
data/shaders/desktop-blur.frag (+17/-0) data/shaders/desktop.frag (+14/-0) data/shaders/desktop.vert (+11/-0) src/android.cpp (+2/-0) src/canvas-android.cpp (+2/-2) src/canvas-x11.cpp (+6/-6) src/main.cpp (+2/-0) src/scene-desktop.cpp (+775/-0) src/scene.h (+19/-0) |
To merge this branch: | bzr merge lp:~linaro-graphics-wg/glmark2/desktop |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jesse Barker | Pending | ||
Review via email: mp+75039@code.launchpad.net |
Commit message
Description of the change
New "desktop" benchmarking scene and one effect (blur).
Jesse Barker (jesse-barker) wrote : | # |
- 139. By Alexandros Frantzis
-
SceneDesktop: Set texture and fbo variables to 0 after deleting their resources.
- 140. By Alexandros Frantzis
-
SceneDesktop: Code cleanup.
Alexandros Frantzis (afrantzis) wrote : | # |
> > +protected:
> > + void draw_quad_
> *texcoord,
> > + Program &program)
>
> Why not make this take "const vector<vec2>& position" and "const
> vector<vec2>& texcoord"? Works just fine with the GL interfaces....
The reasons I am not keen on this are:
1. Currently (ie not C++11) there is no simple way to initialize a static const std::vector.
2. Due to the way the vector is going to be used in the function (&vector[0]), all safety benefits of using std::vector are essentially lost.
3. We don't really need a variable-size container in this case.
Preview Diff
1 | === added file 'data/shaders/desktop-blur.frag' | |||
2 | --- data/shaders/desktop-blur.frag 1970-01-01 00:00:00 +0000 | |||
3 | +++ data/shaders/desktop-blur.frag 2011-09-13 09:41:05 +0000 | |||
4 | @@ -0,0 +1,17 @@ | |||
5 | 1 | #ifdef GL_ES | ||
6 | 2 | precision mediump float; | ||
7 | 3 | #endif | ||
8 | 4 | |||
9 | 5 | uniform sampler2D Texture0; | ||
10 | 6 | |||
11 | 7 | varying vec2 TextureCoord; | ||
12 | 8 | |||
13 | 9 | void main(void) | ||
14 | 10 | { | ||
15 | 11 | vec4 result; | ||
16 | 12 | |||
17 | 13 | $CONVOLUTION$ | ||
18 | 14 | |||
19 | 15 | gl_FragColor = result; | ||
20 | 16 | } | ||
21 | 17 | |||
22 | 0 | 18 | ||
23 | === added file 'data/shaders/desktop.frag' | |||
24 | --- data/shaders/desktop.frag 1970-01-01 00:00:00 +0000 | |||
25 | +++ data/shaders/desktop.frag 2011-09-13 09:41:05 +0000 | |||
26 | @@ -0,0 +1,14 @@ | |||
27 | 1 | #ifdef GL_ES | ||
28 | 2 | precision mediump float; | ||
29 | 3 | #endif | ||
30 | 4 | |||
31 | 5 | uniform sampler2D MaterialTexture0; | ||
32 | 6 | |||
33 | 7 | varying vec2 TextureCoord; | ||
34 | 8 | |||
35 | 9 | void main(void) | ||
36 | 10 | { | ||
37 | 11 | vec4 texel = texture2D(MaterialTexture0, TextureCoord); | ||
38 | 12 | gl_FragColor = texel; | ||
39 | 13 | } | ||
40 | 14 | |||
41 | 0 | 15 | ||
42 | === added file 'data/shaders/desktop.vert' | |||
43 | --- data/shaders/desktop.vert 1970-01-01 00:00:00 +0000 | |||
44 | +++ data/shaders/desktop.vert 2011-09-13 09:41:05 +0000 | |||
45 | @@ -0,0 +1,11 @@ | |||
46 | 1 | attribute vec2 position; | ||
47 | 2 | attribute vec2 texcoord; | ||
48 | 3 | |||
49 | 4 | varying vec2 TextureCoord; | ||
50 | 5 | |||
51 | 6 | void main(void) | ||
52 | 7 | { | ||
53 | 8 | gl_Position = vec4(position, 0.0, 1.0); | ||
54 | 9 | |||
55 | 10 | TextureCoord = texcoord; | ||
56 | 11 | } | ||
57 | 0 | 12 | ||
58 | === added file 'data/textures/desktop-window.png' | |||
59 | 1 | Binary files data/textures/desktop-window.png 1970-01-01 00:00:00 +0000 and data/textures/desktop-window.png 2011-09-13 09:41:05 +0000 differ | 13 | Binary files data/textures/desktop-window.png 1970-01-01 00:00:00 +0000 and data/textures/desktop-window.png 2011-09-13 09:41:05 +0000 differ |
60 | === modified file 'src/android.cpp' | |||
61 | --- src/android.cpp 2011-08-18 15:03:40 +0000 | |||
62 | +++ src/android.cpp 2011-09-13 09:41:05 +0000 | |||
63 | @@ -44,6 +44,7 @@ | |||
64 | 44 | "effect2d:kernel=0,1,0;1,-4,1;0,1,0;", | 44 | "effect2d:kernel=0,1,0;1,-4,1;0,1,0;", |
65 | 45 | "effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;", | 45 | "effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;", |
66 | 46 | "pulsar:quads=5:texture=false:light=false", | 46 | "pulsar:quads=5:texture=false:light=false", |
67 | 47 | "desktop:windows=4:effect=blur:blur-radius=5:passes=1:separable=true", | ||
68 | 47 | "conditionals:vertex-steps=0:fragment-steps=0", | 48 | "conditionals:vertex-steps=0:fragment-steps=0", |
69 | 48 | "conditionals:vertex-steps=0:fragment-steps=5", | 49 | "conditionals:vertex-steps=0:fragment-steps=5", |
70 | 49 | "conditionals:vertex-steps=5:fragment-steps=0", | 50 | "conditionals:vertex-steps=5:fragment-steps=0", |
71 | @@ -85,6 +86,7 @@ | |||
72 | 85 | Benchmark::register_scene(*new SceneBump(*g_canvas)); | 86 | Benchmark::register_scene(*new SceneBump(*g_canvas)); |
73 | 86 | Benchmark::register_scene(*new SceneEffect2D(*g_canvas)); | 87 | Benchmark::register_scene(*new SceneEffect2D(*g_canvas)); |
74 | 87 | Benchmark::register_scene(*new ScenePulsar(*g_canvas)); | 88 | Benchmark::register_scene(*new ScenePulsar(*g_canvas)); |
75 | 89 | Benchmark::register_scene(*new SceneDesktop(canvas)); | ||
76 | 88 | 90 | ||
77 | 89 | add_default_benchmarks(g_benchmarks); | 91 | add_default_benchmarks(g_benchmarks); |
78 | 90 | 92 | ||
79 | 91 | 93 | ||
80 | === modified file 'src/canvas-android.cpp' | |||
81 | --- src/canvas-android.cpp 2011-08-10 18:00:03 +0000 | |||
82 | +++ src/canvas-android.cpp 2011-09-13 09:41:05 +0000 | |||
83 | @@ -35,8 +35,6 @@ | |||
84 | 35 | if (!eglSwapInterval(eglGetCurrentDisplay(), 0)) | 35 | if (!eglSwapInterval(eglGetCurrentDisplay(), 0)) |
85 | 36 | Log::info("** Failed to set swap interval. Results may be bounded above by refresh rate.\n"); | 36 | Log::info("** Failed to set swap interval. Results may be bounded above by refresh rate.\n"); |
86 | 37 | 37 | ||
87 | 38 | glClearColor(0.0f, 0.0f, 0.0f, 0.5f); | ||
88 | 39 | glClearDepthf(1.0f); | ||
89 | 40 | glEnable(GL_DEPTH_TEST); | 38 | glEnable(GL_DEPTH_TEST); |
90 | 41 | glDepthFunc(GL_LEQUAL); | 39 | glDepthFunc(GL_LEQUAL); |
91 | 42 | glEnable(GL_CULL_FACE); | 40 | glEnable(GL_CULL_FACE); |
92 | @@ -56,6 +54,8 @@ | |||
93 | 56 | void | 54 | void |
94 | 57 | CanvasAndroid::clear() | 55 | CanvasAndroid::clear() |
95 | 58 | { | 56 | { |
96 | 57 | glClearColor(0.0f, 0.0f, 0.0f, 0.5f); | ||
97 | 58 | glClearDepthf(1.0f); | ||
98 | 59 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 59 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
99 | 60 | } | 60 | } |
100 | 61 | 61 | ||
101 | 62 | 62 | ||
102 | === modified file 'src/canvas-x11.cpp' | |||
103 | --- src/canvas-x11.cpp 2011-08-09 10:51:03 +0000 | |||
104 | +++ src/canvas-x11.cpp 2011-09-13 09:41:05 +0000 | |||
105 | @@ -84,12 +84,6 @@ | |||
106 | 84 | if (!make_current()) | 84 | if (!make_current()) |
107 | 85 | return false; | 85 | return false; |
108 | 86 | 86 | ||
109 | 87 | glClearColor(0.0f, 0.0f, 0.0f, 0.5f); | ||
110 | 88 | #if USE_GL | ||
111 | 89 | glClearDepth(1.0f); | ||
112 | 90 | #elif USE_GLESv2 | ||
113 | 91 | glClearDepthf(1.0f); | ||
114 | 92 | #endif | ||
115 | 93 | glEnable(GL_DEPTH_TEST); | 87 | glEnable(GL_DEPTH_TEST); |
116 | 94 | glDepthFunc(GL_LEQUAL); | 88 | glDepthFunc(GL_LEQUAL); |
117 | 95 | glEnable(GL_CULL_FACE); | 89 | glEnable(GL_CULL_FACE); |
118 | @@ -110,6 +104,12 @@ | |||
119 | 110 | void | 104 | void |
120 | 111 | CanvasX11::clear() | 105 | CanvasX11::clear() |
121 | 112 | { | 106 | { |
122 | 107 | glClearColor(0.0f, 0.0f, 0.0f, 0.5f); | ||
123 | 108 | #if USE_GL | ||
124 | 109 | glClearDepth(1.0f); | ||
125 | 110 | #elif USE_GLESv2 | ||
126 | 111 | glClearDepthf(1.0f); | ||
127 | 112 | #endif | ||
128 | 113 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 113 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
129 | 114 | } | 114 | } |
130 | 115 | 115 | ||
131 | 116 | 116 | ||
132 | === modified file 'src/main.cpp' | |||
133 | --- src/main.cpp 2011-09-07 09:40:57 +0000 | |||
134 | +++ src/main.cpp 2011-09-13 09:41:05 +0000 | |||
135 | @@ -54,6 +54,7 @@ | |||
136 | 54 | "effect2d:kernel=0,1,0;1,-4,1;0,1,0;", | 54 | "effect2d:kernel=0,1,0;1,-4,1;0,1,0;", |
137 | 55 | "effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;", | 55 | "effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;", |
138 | 56 | "pulsar:quads=5:texture=false:light=false", | 56 | "pulsar:quads=5:texture=false:light=false", |
139 | 57 | "desktop:windows=4:effect=blur:blur-radius=5:passes=1:separable=true", | ||
140 | 57 | "conditionals:vertex-steps=0:fragment-steps=0", | 58 | "conditionals:vertex-steps=0:fragment-steps=0", |
141 | 58 | "conditionals:vertex-steps=0:fragment-steps=5", | 59 | "conditionals:vertex-steps=0:fragment-steps=5", |
142 | 59 | "conditionals:vertex-steps=5:fragment-steps=0", | 60 | "conditionals:vertex-steps=5:fragment-steps=0", |
143 | @@ -96,6 +97,7 @@ | |||
144 | 96 | scenes.push_back(new SceneBump(canvas)); | 97 | scenes.push_back(new SceneBump(canvas)); |
145 | 97 | scenes.push_back(new SceneEffect2D(canvas)); | 98 | scenes.push_back(new SceneEffect2D(canvas)); |
146 | 98 | scenes.push_back(new ScenePulsar(canvas)); | 99 | scenes.push_back(new ScenePulsar(canvas)); |
147 | 100 | scenes.push_back(new SceneDesktop(canvas)); | ||
148 | 99 | 101 | ||
149 | 100 | for (vector<Scene*>::const_iterator iter = scenes.begin(); | 102 | for (vector<Scene*>::const_iterator iter = scenes.begin(); |
150 | 101 | iter != scenes.end(); | 103 | iter != scenes.end(); |
151 | 102 | 104 | ||
152 | === added file 'src/scene-desktop.cpp' | |||
153 | --- src/scene-desktop.cpp 1970-01-01 00:00:00 +0000 | |||
154 | +++ src/scene-desktop.cpp 2011-09-13 09:41:05 +0000 | |||
155 | @@ -0,0 +1,775 @@ | |||
156 | 1 | /* | ||
157 | 2 | * Copyright © 2010-2011 Linaro Limited | ||
158 | 3 | * | ||
159 | 4 | * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark. | ||
160 | 5 | * | ||
161 | 6 | * glmark2 is free software: you can redistribute it and/or modify it under the | ||
162 | 7 | * terms of the GNU General Public License as published by the Free Software | ||
163 | 8 | * Foundation, either version 3 of the License, or (at your option) any later | ||
164 | 9 | * version. | ||
165 | 10 | * | ||
166 | 11 | * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY | ||
167 | 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
168 | 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
169 | 14 | * details. | ||
170 | 15 | * | ||
171 | 16 | * You should have received a copy of the GNU General Public License along with | ||
172 | 17 | * glmark2. If not, see <http://www.gnu.org/licenses/>. | ||
173 | 18 | * | ||
174 | 19 | * Authors: | ||
175 | 20 | * Alexandros Frantzis (glmark2) | ||
176 | 21 | */ | ||
177 | 22 | #include <cmath> | ||
178 | 23 | |||
179 | 24 | #include "scene.h" | ||
180 | 25 | #include "mat.h" | ||
181 | 26 | #include "stack.h" | ||
182 | 27 | #include "vec.h" | ||
183 | 28 | #include "log.h" | ||
184 | 29 | #include "program.h" | ||
185 | 30 | #include "shader-source.h" | ||
186 | 31 | #include "util.h" | ||
187 | 32 | |||
188 | 33 | enum BlurDirection { | ||
189 | 34 | BlurDirectionHorizontal, | ||
190 | 35 | BlurDirectionVertical, | ||
191 | 36 | BlurDirectionBoth | ||
192 | 37 | }; | ||
193 | 38 | |||
194 | 39 | static void | ||
195 | 40 | create_blur_shaders(ShaderSource& vtx_source, ShaderSource& frg_source, | ||
196 | 41 | unsigned int radius, float sigma, BlurDirection direction) | ||
197 | 42 | { | ||
198 | 43 | vtx_source.append_file(GLMARK_DATA_PATH"/shaders/desktop.vert"); | ||
199 | 44 | frg_source.append_file(GLMARK_DATA_PATH"/shaders/desktop-blur.frag"); | ||
200 | 45 | |||
201 | 46 | /* Don't let the gaussian curve become too narrow */ | ||
202 | 47 | if (sigma < 1.0) | ||
203 | 48 | sigma = 1.0; | ||
204 | 49 | |||
205 | 50 | unsigned int side = 2 * radius + 1; | ||
206 | 51 | |||
207 | 52 | for (size_t i = 0; i < radius + 1; i++) { | ||
208 | 53 | float s2 = 2.0 * sigma * sigma; | ||
209 | 54 | float k = 1.0 / std::sqrt(M_PI * s2) * std::exp( - ((float)i * i) / s2); | ||
210 | 55 | std::stringstream ss_tmp; | ||
211 | 56 | ss_tmp << "Kernel" << i; | ||
212 | 57 | frg_source.add_const(ss_tmp.str(), k); | ||
213 | 58 | } | ||
214 | 59 | |||
215 | 60 | std::stringstream ss; | ||
216 | 61 | ss << "result = " << std::endl; | ||
217 | 62 | |||
218 | 63 | if (direction == BlurDirectionHorizontal) { | ||
219 | 64 | for (size_t i = 0; i < side; i++) { | ||
220 | 65 | int offset = (int)(i - radius); | ||
221 | 66 | ss << "texture2D(Texture0, TextureCoord + vec2(" << | ||
222 | 67 | offset << ".0 * TextureStepX, 0.0)) * Kernel" << | ||
223 | 68 | std::abs(offset) << " +" << std::endl; | ||
224 | 69 | } | ||
225 | 70 | ss << "0.0 ;" << std::endl; | ||
226 | 71 | } | ||
227 | 72 | else if (direction == BlurDirectionVertical) { | ||
228 | 73 | for (size_t i = 0; i < side; i++) { | ||
229 | 74 | int offset = (int)(i - radius); | ||
230 | 75 | ss << "texture2D(Texture0, TextureCoord + vec2(0.0, " << | ||
231 | 76 | offset << ".0 * TextureStepY)) * Kernel" << | ||
232 | 77 | std::abs(offset) << " +" << std::endl; | ||
233 | 78 | } | ||
234 | 79 | ss << "0.0 ;" << std::endl; | ||
235 | 80 | } | ||
236 | 81 | else if (direction == BlurDirectionBoth) { | ||
237 | 82 | for (size_t i = 0; i < side; i++) { | ||
238 | 83 | int ioffset = (int)(i - radius); | ||
239 | 84 | for (size_t j = 0; j < side; j++) { | ||
240 | 85 | int joffset = (int)(j - radius); | ||
241 | 86 | ss << "texture2D(Texture0, TextureCoord + vec2(" << | ||
242 | 87 | ioffset << ".0 * TextureStepX, " << | ||
243 | 88 | joffset << ".0 * TextureStepY))" << | ||
244 | 89 | " * Kernel" << std::abs(ioffset) << | ||
245 | 90 | " * Kernel" << std::abs(joffset) << " +" << std::endl; | ||
246 | 91 | } | ||
247 | 92 | } | ||
248 | 93 | ss << " 0.0;" << std::endl; | ||
249 | 94 | } | ||
250 | 95 | |||
251 | 96 | frg_source.replace("$CONVOLUTION$", ss.str()); | ||
252 | 97 | } | ||
253 | 98 | |||
254 | 99 | /** | ||
255 | 100 | * A RenderObject represents a source and target of rendering | ||
256 | 101 | * operations. | ||
257 | 102 | */ | ||
258 | 103 | class RenderObject | ||
259 | 104 | { | ||
260 | 105 | public: | ||
261 | 106 | RenderObject() : texture_(0), fbo_(0) { } | ||
262 | 107 | |||
263 | 108 | virtual ~RenderObject() { release(); } | ||
264 | 109 | |||
265 | 110 | virtual void init() | ||
266 | 111 | { | ||
267 | 112 | /* Create a texture to draw to */ | ||
268 | 113 | glGenTextures(1, &texture_); | ||
269 | 114 | glBindTexture(GL_TEXTURE_2D, texture_); | ||
270 | 115 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
271 | 116 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
272 | 117 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
273 | 118 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
274 | 119 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.x(), size_.y(), 0, | ||
275 | 120 | GL_RGBA, GL_UNSIGNED_BYTE, 0); | ||
276 | 121 | |||
277 | 122 | /* Create a FBO */ | ||
278 | 123 | glGenFramebuffers(1, &fbo_); | ||
279 | 124 | glBindFramebuffer(GL_FRAMEBUFFER, fbo_); | ||
280 | 125 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | ||
281 | 126 | GL_TEXTURE_2D, texture_, 0); | ||
282 | 127 | |||
283 | 128 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
284 | 129 | |||
285 | 130 | /* Load the shader program when this class if first used */ | ||
286 | 131 | if (RenderObject::use_count == 0) { | ||
287 | 132 | ShaderSource vtx_source(GLMARK_DATA_PATH"/shaders/desktop.vert"); | ||
288 | 133 | ShaderSource frg_source(GLMARK_DATA_PATH"/shaders/desktop.frag"); | ||
289 | 134 | Scene::load_shaders_from_strings(main_program, vtx_source.str(), | ||
290 | 135 | frg_source.str()); | ||
291 | 136 | } | ||
292 | 137 | |||
293 | 138 | RenderObject::use_count++; | ||
294 | 139 | } | ||
295 | 140 | |||
296 | 141 | virtual void release() | ||
297 | 142 | { | ||
298 | 143 | /* Release resources */ | ||
299 | 144 | glDeleteTextures(1, &texture_); | ||
300 | 145 | glDeleteFramebuffers(1, &fbo_); | ||
301 | 146 | texture_ = 0; | ||
302 | 147 | fbo_ = 0; | ||
303 | 148 | |||
304 | 149 | /* | ||
305 | 150 | * Release the shader program when object of this class | ||
306 | 151 | * are no longer in use. | ||
307 | 152 | */ | ||
308 | 153 | RenderObject::use_count--; | ||
309 | 154 | if (RenderObject::use_count == 0) | ||
310 | 155 | RenderObject::main_program.release(); | ||
311 | 156 | } | ||
312 | 157 | |||
313 | 158 | void make_current() | ||
314 | 159 | { | ||
315 | 160 | glBindFramebuffer(GL_FRAMEBUFFER, fbo_); | ||
316 | 161 | glViewport(0, 0, size_.x(), size_.y()); | ||
317 | 162 | } | ||
318 | 163 | |||
319 | 164 | void position(const LibMatrix::vec2& pos) { pos_ = pos; } | ||
320 | 165 | const LibMatrix::vec2& position() { return pos_; } | ||
321 | 166 | |||
322 | 167 | |||
323 | 168 | virtual void size(const LibMatrix::vec2& size) | ||
324 | 169 | { | ||
325 | 170 | /* Recreate the backing texture with correct size */ | ||
326 | 171 | if (size_.x() != size.x() || size_.y() != size.y()) { | ||
327 | 172 | size_ = size; | ||
328 | 173 | glBindTexture(GL_TEXTURE_2D, texture_); | ||
329 | 174 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.x(), size_.y(), 0, | ||
330 | 175 | GL_RGBA, GL_UNSIGNED_BYTE, 0); | ||
331 | 176 | clear(); | ||
332 | 177 | } | ||
333 | 178 | } | ||
334 | 179 | |||
335 | 180 | const LibMatrix::vec2& size() { return size_; } | ||
336 | 181 | |||
337 | 182 | const LibMatrix::vec2& speed() { return speed_; } | ||
338 | 183 | void speed(const LibMatrix::vec2& speed) { speed_ = speed; } | ||
339 | 184 | |||
340 | 185 | GLuint texture() { return texture_; } | ||
341 | 186 | |||
342 | 187 | virtual void clear() | ||
343 | 188 | { | ||
344 | 189 | make_current(); | ||
345 | 190 | glClear(GL_COLOR_BUFFER_BIT); | ||
346 | 191 | } | ||
347 | 192 | |||
348 | 193 | virtual void render_to(RenderObject& target, Program& program = main_program) | ||
349 | 194 | { | ||
350 | 195 | LibMatrix::vec2 final_pos(pos_ + size_); | ||
351 | 196 | LibMatrix::vec2 ll(target.normalize_position(pos_)); | ||
352 | 197 | LibMatrix::vec2 ur(target.normalize_position(final_pos)); | ||
353 | 198 | |||
354 | 199 | GLfloat position[2 * 4] = { | ||
355 | 200 | ll.x(), ll.y(), | ||
356 | 201 | ur.x(), ll.y(), | ||
357 | 202 | ll.x(), ur.y(), | ||
358 | 203 | ur.x(), ur.y(), | ||
359 | 204 | }; | ||
360 | 205 | |||
361 | 206 | static const GLfloat texcoord[2 * 4] = { | ||
362 | 207 | 0.0, 0.0, | ||
363 | 208 | 1.0, 0.0, | ||
364 | 209 | 0.0, 1.0, | ||
365 | 210 | 1.0, 1.0, | ||
366 | 211 | }; | ||
367 | 212 | |||
368 | 213 | target.make_current(); | ||
369 | 214 | |||
370 | 215 | glActiveTexture(GL_TEXTURE0); | ||
371 | 216 | glBindTexture(GL_TEXTURE_2D, texture_); | ||
372 | 217 | draw_quad_with_program(position, texcoord, program); | ||
373 | 218 | } | ||
374 | 219 | |||
375 | 220 | virtual void render_from(RenderObject& target, Program& program = main_program) | ||
376 | 221 | { | ||
377 | 222 | LibMatrix::vec2 final_pos(pos_ + size_); | ||
378 | 223 | LibMatrix::vec2 ll_tex(target.normalize_texcoord(pos_)); | ||
379 | 224 | LibMatrix::vec2 ur_tex(target.normalize_texcoord(final_pos)); | ||
380 | 225 | |||
381 | 226 | static const GLfloat position_blur[2 * 4] = { | ||
382 | 227 | -1.0, -1.0, | ||
383 | 228 | 1.0, -1.0, | ||
384 | 229 | -1.0, 1.0, | ||
385 | 230 | 1.0, 1.0, | ||
386 | 231 | }; | ||
387 | 232 | GLfloat texcoord_blur[2 * 4] = { | ||
388 | 233 | ll_tex.x(), ll_tex.y(), | ||
389 | 234 | ur_tex.x(), ll_tex.y(), | ||
390 | 235 | ll_tex.x(), ur_tex.y(), | ||
391 | 236 | ur_tex.x(), ur_tex.y(), | ||
392 | 237 | }; | ||
393 | 238 | |||
394 | 239 | make_current(); | ||
395 | 240 | glBindTexture(GL_TEXTURE_2D, target.texture()); | ||
396 | 241 | draw_quad_with_program(position_blur, texcoord_blur, program); | ||
397 | 242 | } | ||
398 | 243 | |||
399 | 244 | /** | ||
400 | 245 | * Normalizes a position from [0, size] to [-1.0, 1.0] | ||
401 | 246 | */ | ||
402 | 247 | LibMatrix::vec2 normalize_position(LibMatrix::vec2& pos) | ||
403 | 248 | { | ||
404 | 249 | return LibMatrix::vec2(2.0 * pos.x() / size_.x() - 1.0, | ||
405 | 250 | 2.0 * pos.y() / size_.y() - 1.0); | ||
406 | 251 | } | ||
407 | 252 | |||
408 | 253 | /** | ||
409 | 254 | * Normalizes a position from [0, size] to [0.0, 1.0] | ||
410 | 255 | */ | ||
411 | 256 | LibMatrix::vec2 normalize_texcoord(LibMatrix::vec2& pos) | ||
412 | 257 | { | ||
413 | 258 | return LibMatrix::vec2(pos.x() / size_.x(), | ||
414 | 259 | pos.y() / size_.y()); | ||
415 | 260 | } | ||
416 | 261 | |||
417 | 262 | |||
418 | 263 | protected: | ||
419 | 264 | void draw_quad_with_program(const GLfloat *position, const GLfloat *texcoord, | ||
420 | 265 | Program &program) | ||
421 | 266 | { | ||
422 | 267 | int pos_index = program["position"].location(); | ||
423 | 268 | int tex_index = program["texcoord"].location(); | ||
424 | 269 | |||
425 | 270 | program.start(); | ||
426 | 271 | |||
427 | 272 | glEnableVertexAttribArray(pos_index); | ||
428 | 273 | glEnableVertexAttribArray(tex_index); | ||
429 | 274 | glVertexAttribPointer(pos_index, 2, | ||
430 | 275 | GL_FLOAT, GL_FALSE, 0, position); | ||
431 | 276 | glVertexAttribPointer(tex_index, 2, | ||
432 | 277 | GL_FLOAT, GL_FALSE, 0, texcoord); | ||
433 | 278 | |||
434 | 279 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
435 | 280 | |||
436 | 281 | glDisableVertexAttribArray(tex_index); | ||
437 | 282 | glDisableVertexAttribArray(pos_index); | ||
438 | 283 | |||
439 | 284 | program.stop(); | ||
440 | 285 | } | ||
441 | 286 | |||
442 | 287 | static Program main_program; | ||
443 | 288 | |||
444 | 289 | LibMatrix::vec2 pos_; | ||
445 | 290 | LibMatrix::vec2 size_; | ||
446 | 291 | LibMatrix::vec2 speed_; | ||
447 | 292 | GLuint texture_; | ||
448 | 293 | GLuint fbo_; | ||
449 | 294 | |||
450 | 295 | private: | ||
451 | 296 | static int use_count; | ||
452 | 297 | |||
453 | 298 | }; | ||
454 | 299 | |||
455 | 300 | int RenderObject::use_count = 0; | ||
456 | 301 | Program RenderObject::main_program; | ||
457 | 302 | |||
458 | 303 | /** | ||
459 | 304 | * A RenderObject representing the screen. | ||
460 | 305 | * | ||
461 | 306 | * Rendering to this objects renders to the screen framebuffer. | ||
462 | 307 | */ | ||
463 | 308 | class RenderScreen : public RenderObject | ||
464 | 309 | { | ||
465 | 310 | public: | ||
466 | 311 | virtual void init() {} | ||
467 | 312 | }; | ||
468 | 313 | |||
469 | 314 | /** | ||
470 | 315 | * A RenderObject with a background image. | ||
471 | 316 | * | ||
472 | 317 | * The image is drawn to the RenderObject automatically when the | ||
473 | 318 | * object is cleared, resized etc | ||
474 | 319 | */ | ||
475 | 320 | class RenderClearImage : public RenderObject | ||
476 | 321 | { | ||
477 | 322 | public: | ||
478 | 323 | RenderClearImage(const std::string& texture) : | ||
479 | 324 | RenderObject(), background_texture_name(texture), | ||
480 | 325 | background_texture_(0) {} | ||
481 | 326 | |||
482 | 327 | virtual void init() | ||
483 | 328 | { | ||
484 | 329 | RenderObject::init(); | ||
485 | 330 | |||
486 | 331 | /* Load the image into a texture */ | ||
487 | 332 | Texture::load(background_texture_name, | ||
488 | 333 | &background_texture_, GL_LINEAR, GL_LINEAR, 0); | ||
489 | 334 | |||
490 | 335 | } | ||
491 | 336 | |||
492 | 337 | virtual void release() | ||
493 | 338 | { | ||
494 | 339 | glDeleteTextures(1, &background_texture_); | ||
495 | 340 | background_texture_ = 0; | ||
496 | 341 | |||
497 | 342 | RenderObject::release(); | ||
498 | 343 | } | ||
499 | 344 | |||
500 | 345 | virtual void clear() | ||
501 | 346 | { | ||
502 | 347 | static const GLfloat position[2 * 4] = { | ||
503 | 348 | -1.0, -1.0, | ||
504 | 349 | 1.0, -1.0, | ||
505 | 350 | -1.0, 1.0, | ||
506 | 351 | 1.0, 1.0, | ||
507 | 352 | }; | ||
508 | 353 | static const GLfloat texcoord[2 * 4] = { | ||
509 | 354 | 0.0, 0.0, | ||
510 | 355 | 1.0, 0.0, | ||
511 | 356 | 0.0, 1.0, | ||
512 | 357 | 1.0, 1.0, | ||
513 | 358 | }; | ||
514 | 359 | |||
515 | 360 | make_current(); | ||
516 | 361 | glClear(GL_COLOR_BUFFER_BIT); | ||
517 | 362 | |||
518 | 363 | glActiveTexture(GL_TEXTURE0); | ||
519 | 364 | glBindTexture(GL_TEXTURE_2D, background_texture_); | ||
520 | 365 | |||
521 | 366 | glEnable(GL_BLEND); | ||
522 | 367 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
523 | 368 | draw_quad_with_program(position, texcoord, main_program); | ||
524 | 369 | glDisable(GL_BLEND); | ||
525 | 370 | } | ||
526 | 371 | |||
527 | 372 | private: | ||
528 | 373 | std::string background_texture_name; | ||
529 | 374 | GLuint background_texture_; | ||
530 | 375 | }; | ||
531 | 376 | |||
532 | 377 | /** | ||
533 | 378 | * A RenderObject that blurs the target it is drawn to. | ||
534 | 379 | */ | ||
535 | 380 | class RenderWindowBlur : public RenderObject | ||
536 | 381 | { | ||
537 | 382 | public: | ||
538 | 383 | RenderWindowBlur(unsigned int passes, unsigned int radius, bool separable, | ||
539 | 384 | bool draw_contents = true) : | ||
540 | 385 | RenderObject(), passes_(passes), radius_(radius), separable_(separable), | ||
541 | 386 | draw_contents_(draw_contents) {} | ||
542 | 387 | |||
543 | 388 | virtual void init() | ||
544 | 389 | { | ||
545 | 390 | RenderObject::init(); | ||
546 | 391 | |||
547 | 392 | /* Only have one instance of the window contents data */ | ||
548 | 393 | if (draw_contents_ && RenderWindowBlur::use_count == 0) | ||
549 | 394 | window_contents_.init(); | ||
550 | 395 | |||
551 | 396 | RenderWindowBlur::use_count++; | ||
552 | 397 | } | ||
553 | 398 | |||
554 | 399 | virtual void release() | ||
555 | 400 | { | ||
556 | 401 | RenderWindowBlur::use_count--; | ||
557 | 402 | |||
558 | 403 | /* Only have one instance of the window contents data */ | ||
559 | 404 | if (draw_contents_ && RenderWindowBlur::use_count == 0) | ||
560 | 405 | window_contents_.release(); | ||
561 | 406 | |||
562 | 407 | RenderObject::release(); | ||
563 | 408 | } | ||
564 | 409 | |||
565 | 410 | virtual void size(const LibMatrix::vec2& size) | ||
566 | 411 | { | ||
567 | 412 | RenderObject::size(size); | ||
568 | 413 | if (draw_contents_) | ||
569 | 414 | window_contents_.size(size); | ||
570 | 415 | } | ||
571 | 416 | |||
572 | 417 | virtual void render_to(RenderObject& target, Program& program) | ||
573 | 418 | { | ||
574 | 419 | (void)program; | ||
575 | 420 | |||
576 | 421 | if (separable_) { | ||
577 | 422 | Program& blur_program_h1 = blur_program_h(target.size().x()); | ||
578 | 423 | Program& blur_program_v1 = blur_program_v(target.size().y()); | ||
579 | 424 | |||
580 | 425 | for (unsigned int i = 0; i < passes_; i++) { | ||
581 | 426 | render_from(target, blur_program_h1); | ||
582 | 427 | RenderObject::render_to(target, blur_program_v1); | ||
583 | 428 | } | ||
584 | 429 | } | ||
585 | 430 | else { | ||
586 | 431 | Program& blur_program1 = blur_program(target.size().x(), target.size().y()); | ||
587 | 432 | |||
588 | 433 | for (unsigned int i = 0; i < passes_; i++) { | ||
589 | 434 | if (i % 2 == 0) | ||
590 | 435 | render_from(target, blur_program1); | ||
591 | 436 | else | ||
592 | 437 | RenderObject::render_to(target, blur_program1); | ||
593 | 438 | } | ||
594 | 439 | |||
595 | 440 | if (passes_ % 2 == 1) | ||
596 | 441 | RenderObject::render_to(target); | ||
597 | 442 | } | ||
598 | 443 | |||
599 | 444 | /* | ||
600 | 445 | * Blend the window contents with the target texture. | ||
601 | 446 | */ | ||
602 | 447 | if (draw_contents_) { | ||
603 | 448 | glEnable(GL_BLEND); | ||
604 | 449 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
605 | 450 | window_contents_.position(position()); | ||
606 | 451 | window_contents_.render_to(target); | ||
607 | 452 | glDisable(GL_BLEND); | ||
608 | 453 | } | ||
609 | 454 | } | ||
610 | 455 | |||
611 | 456 | private: | ||
612 | 457 | Program& blur_program(unsigned int w, unsigned int h) | ||
613 | 458 | { | ||
614 | 459 | /* | ||
615 | 460 | * If the size of the window has changed we must recreate | ||
616 | 461 | * the shader to contain the correct texture step values. | ||
617 | 462 | */ | ||
618 | 463 | if (blur_program_dim_.x() != w || blur_program_dim_.y() != h || | ||
619 | 464 | !blur_program_.ready()) | ||
620 | 465 | { | ||
621 | 466 | blur_program_dim_.x(w); | ||
622 | 467 | blur_program_dim_.y(h); | ||
623 | 468 | |||
624 | 469 | blur_program_.release(); | ||
625 | 470 | |||
626 | 471 | ShaderSource vtx_source; | ||
627 | 472 | ShaderSource frg_source; | ||
628 | 473 | create_blur_shaders(vtx_source, frg_source, radius_, | ||
629 | 474 | radius_ / 3.0, BlurDirectionBoth); | ||
630 | 475 | frg_source.add_const("TextureStepX", 1.0 / w); | ||
631 | 476 | frg_source.add_const("TextureStepY", 1.0 / h); | ||
632 | 477 | Scene::load_shaders_from_strings(blur_program_, vtx_source.str(), | ||
633 | 478 | frg_source.str()); | ||
634 | 479 | } | ||
635 | 480 | |||
636 | 481 | return blur_program_; | ||
637 | 482 | } | ||
638 | 483 | |||
639 | 484 | Program& blur_program_h(unsigned int w) | ||
640 | 485 | { | ||
641 | 486 | /* | ||
642 | 487 | * If the size of the window has changed we must recreate | ||
643 | 488 | * the shader to contain the correct texture step values. | ||
644 | 489 | */ | ||
645 | 490 | if (blur_program_dim_.x() != w || | ||
646 | 491 | !blur_program_h_.ready()) | ||
647 | 492 | { | ||
648 | 493 | blur_program_dim_.x(w); | ||
649 | 494 | |||
650 | 495 | blur_program_h_.release(); | ||
651 | 496 | |||
652 | 497 | ShaderSource vtx_source; | ||
653 | 498 | ShaderSource frg_source; | ||
654 | 499 | create_blur_shaders(vtx_source, frg_source, radius_, | ||
655 | 500 | radius_ / 3.0, BlurDirectionHorizontal); | ||
656 | 501 | frg_source.add_const("TextureStepX", 1.0 / w); | ||
657 | 502 | Scene::load_shaders_from_strings(blur_program_h_, vtx_source.str(), | ||
658 | 503 | frg_source.str()); | ||
659 | 504 | } | ||
660 | 505 | |||
661 | 506 | return blur_program_h_; | ||
662 | 507 | } | ||
663 | 508 | |||
664 | 509 | Program& blur_program_v(unsigned int h) | ||
665 | 510 | { | ||
666 | 511 | /* | ||
667 | 512 | * If the size of the window has changed we must recreate | ||
668 | 513 | * the shader to contain the correct texture step values. | ||
669 | 514 | */ | ||
670 | 515 | if (blur_program_dim_.y() != h || | ||
671 | 516 | !blur_program_v_.ready()) | ||
672 | 517 | { | ||
673 | 518 | blur_program_dim_.y(h); | ||
674 | 519 | |||
675 | 520 | blur_program_v_.release(); | ||
676 | 521 | |||
677 | 522 | ShaderSource vtx_source; | ||
678 | 523 | ShaderSource frg_source; | ||
679 | 524 | create_blur_shaders(vtx_source, frg_source, radius_, | ||
680 | 525 | radius_ / 3.0, BlurDirectionVertical); | ||
681 | 526 | frg_source.add_const("TextureStepY", 1.0 / h); | ||
682 | 527 | Scene::load_shaders_from_strings(blur_program_v_, vtx_source.str(), | ||
683 | 528 | frg_source.str()); | ||
684 | 529 | } | ||
685 | 530 | |||
686 | 531 | return blur_program_v_; | ||
687 | 532 | } | ||
688 | 533 | |||
689 | 534 | LibMatrix::uvec2 blur_program_dim_; | ||
690 | 535 | Program blur_program_; | ||
691 | 536 | Program blur_program_h_; | ||
692 | 537 | Program blur_program_v_; | ||
693 | 538 | unsigned int passes_; | ||
694 | 539 | unsigned int radius_; | ||
695 | 540 | bool separable_; | ||
696 | 541 | bool draw_contents_; | ||
697 | 542 | |||
698 | 543 | static int use_count; | ||
699 | 544 | static RenderClearImage window_contents_; | ||
700 | 545 | |||
701 | 546 | }; | ||
702 | 547 | |||
703 | 548 | int RenderWindowBlur::use_count = 0; | ||
704 | 549 | RenderClearImage RenderWindowBlur::window_contents_(GLMARK_DATA_PATH"/textures/desktop-window.png"); | ||
705 | 550 | |||
706 | 551 | /******************************* | ||
707 | 552 | * SceneDesktop implementation * | ||
708 | 553 | *******************************/ | ||
709 | 554 | |||
710 | 555 | /** | ||
711 | 556 | * Private structure used to avoid contaminating scene.h with all of the | ||
712 | 557 | * SceneDesktop internal classes. | ||
713 | 558 | */ | ||
714 | 559 | struct SceneDesktopPrivate | ||
715 | 560 | { | ||
716 | 561 | RenderScreen screen; | ||
717 | 562 | RenderClearImage desktop; | ||
718 | 563 | std::vector<RenderObject *> windows; | ||
719 | 564 | |||
720 | 565 | SceneDesktopPrivate() : | ||
721 | 566 | desktop(GLMARK_DATA_PATH"/textures/effect-2d.png") {} | ||
722 | 567 | |||
723 | 568 | ~SceneDesktopPrivate() { Util::dispose_pointer_vector(windows); } | ||
724 | 569 | |||
725 | 570 | }; | ||
726 | 571 | |||
727 | 572 | |||
728 | 573 | SceneDesktop::SceneDesktop(Canvas &canvas) : | ||
729 | 574 | Scene(canvas, "desktop") | ||
730 | 575 | { | ||
731 | 576 | priv_ = new SceneDesktopPrivate(); | ||
732 | 577 | mOptions["effect"] = Scene::Option("effect", "blur", | ||
733 | 578 | "the effect to use [blur]"); | ||
734 | 579 | mOptions["windows"] = Scene::Option("windows", "4", | ||
735 | 580 | "the number of windows"); | ||
736 | 581 | mOptions["window-size"] = Scene::Option("window-size", "0.35", | ||
737 | 582 | "the window size as a percentage of the minimum screen dimension [0.0 - 0.5]"); | ||
738 | 583 | mOptions["passes"] = Scene::Option("passes", "1", | ||
739 | 584 | "the number of effect passes (effect dependent)"); | ||
740 | 585 | mOptions["blur-radius"] = Scene::Option("blur-radius", "5", | ||
741 | 586 | "the blur effect radius (in pixels)"); | ||
742 | 587 | mOptions["separable"] = Scene::Option("separable", "true", | ||
743 | 588 | "use separable convolution for the blur effect"); | ||
744 | 589 | } | ||
745 | 590 | |||
746 | 591 | SceneDesktop::~SceneDesktop() | ||
747 | 592 | { | ||
748 | 593 | delete priv_; | ||
749 | 594 | } | ||
750 | 595 | |||
751 | 596 | int | ||
752 | 597 | SceneDesktop::load() | ||
753 | 598 | { | ||
754 | 599 | priv_->screen.init(); | ||
755 | 600 | priv_->desktop.init(); | ||
756 | 601 | return 1; | ||
757 | 602 | } | ||
758 | 603 | |||
759 | 604 | void | ||
760 | 605 | SceneDesktop::unload() | ||
761 | 606 | { | ||
762 | 607 | priv_->desktop.release(); | ||
763 | 608 | priv_->screen.release(); | ||
764 | 609 | } | ||
765 | 610 | |||
766 | 611 | void | ||
767 | 612 | SceneDesktop::setup() | ||
768 | 613 | { | ||
769 | 614 | Scene::setup(); | ||
770 | 615 | |||
771 | 616 | std::stringstream ss; | ||
772 | 617 | unsigned int windows(0); | ||
773 | 618 | unsigned int passes(0); | ||
774 | 619 | unsigned int blur_radius(0); | ||
775 | 620 | float window_size_factor(0.0); | ||
776 | 621 | bool separable(mOptions["separable"].value == "true"); | ||
777 | 622 | |||
778 | 623 | ss << mOptions["windows"].value; | ||
779 | 624 | ss >> windows; | ||
780 | 625 | ss.clear(); | ||
781 | 626 | ss << mOptions["window-size"].value; | ||
782 | 627 | ss >> window_size_factor; | ||
783 | 628 | ss.clear(); | ||
784 | 629 | ss << mOptions["passes"].value; | ||
785 | 630 | ss >> passes; | ||
786 | 631 | ss.clear(); | ||
787 | 632 | ss << mOptions["blur-radius"].value; | ||
788 | 633 | ss >> blur_radius; | ||
789 | 634 | |||
790 | 635 | /* Ensure we get a transparent clear color for all following operations */ | ||
791 | 636 | glClearColor(0.0, 0.0, 0.0, 0.0); | ||
792 | 637 | glDisable(GL_DEPTH_TEST); | ||
793 | 638 | glDepthMask(GL_FALSE); | ||
794 | 639 | |||
795 | 640 | /* Set up the screen and desktop RenderObjects */ | ||
796 | 641 | priv_->screen.size(LibMatrix::vec2(mCanvas.width(), mCanvas.height())); | ||
797 | 642 | priv_->desktop.size(LibMatrix::vec2(mCanvas.width(), mCanvas.height())); | ||
798 | 643 | |||
799 | 644 | /* Create the windows */ | ||
800 | 645 | float angular_step(2.0 * M_PI / windows); | ||
801 | 646 | unsigned int min_dimension = std::min(mCanvas.width(), mCanvas.height()); | ||
802 | 647 | float window_size(min_dimension * window_size_factor); | ||
803 | 648 | static const LibMatrix::vec2 corner_offset(window_size / 2.0, | ||
804 | 649 | window_size / 2.0); | ||
805 | 650 | |||
806 | 651 | for (unsigned int i = 0; i < windows; i++) { | ||
807 | 652 | LibMatrix::vec2 center(mCanvas.width() * (0.5 + 0.25 * cos(i * angular_step)), | ||
808 | 653 | mCanvas.height() * (0.5 + 0.25 * sin(i * angular_step))); | ||
809 | 654 | RenderObject* win(new RenderWindowBlur(passes, blur_radius, separable)); | ||
810 | 655 | (void)angular_step; | ||
811 | 656 | |||
812 | 657 | win->init(); | ||
813 | 658 | win->position(center - corner_offset); | ||
814 | 659 | win->size(LibMatrix::vec2(window_size, window_size)); | ||
815 | 660 | /* | ||
816 | 661 | * Set the speed in increments of about 30 degrees (but not exactly, | ||
817 | 662 | * so we don't get windows moving just on the X axis or Y axis). | ||
818 | 663 | */ | ||
819 | 664 | win->speed(LibMatrix::vec2(cos(0.1 + i * M_PI / 6.0) * mCanvas.width() / 3, | ||
820 | 665 | sin(0.1 + i * M_PI / 6.0) * mCanvas.height() / 3)); | ||
821 | 666 | /* | ||
822 | 667 | * Perform a dummy rendering to ensure internal shaders are initialized | ||
823 | 668 | * now, in order not to affect the benchmarking. | ||
824 | 669 | */ | ||
825 | 670 | win->render_to(priv_->desktop); | ||
826 | 671 | priv_->windows.push_back(win); | ||
827 | 672 | } | ||
828 | 673 | |||
829 | 674 | /* | ||
830 | 675 | * Ensure the screen is the current rendering target (it might have changed | ||
831 | 676 | * to a FBO in the previous steps). | ||
832 | 677 | */ | ||
833 | 678 | priv_->screen.make_current(); | ||
834 | 679 | |||
835 | 680 | mCurrentFrame = 0; | ||
836 | 681 | mRunning = true; | ||
837 | 682 | mStartTime = Scene::get_timestamp_us() / 1000000.0; | ||
838 | 683 | mLastUpdateTime = mStartTime; | ||
839 | 684 | } | ||
840 | 685 | |||
841 | 686 | void | ||
842 | 687 | SceneDesktop::teardown() | ||
843 | 688 | { | ||
844 | 689 | Util::dispose_pointer_vector(priv_->windows); | ||
845 | 690 | priv_->screen.make_current(); | ||
846 | 691 | |||
847 | 692 | glEnable(GL_DEPTH_TEST); | ||
848 | 693 | glDepthMask(GL_TRUE); | ||
849 | 694 | |||
850 | 695 | Scene::teardown(); | ||
851 | 696 | } | ||
852 | 697 | |||
853 | 698 | void | ||
854 | 699 | SceneDesktop::update() | ||
855 | 700 | { | ||
856 | 701 | double current_time = Scene::get_timestamp_us() / 1000000.0; | ||
857 | 702 | double dt = current_time - mLastUpdateTime; | ||
858 | 703 | double elapsed_time = current_time - mStartTime; | ||
859 | 704 | |||
860 | 705 | mLastUpdateTime = current_time; | ||
861 | 706 | |||
862 | 707 | std::vector<RenderObject *>& windows(priv_->windows); | ||
863 | 708 | |||
864 | 709 | /* | ||
865 | 710 | * Move the windows around the screen, bouncing them back when | ||
866 | 711 | * they reach the edge. | ||
867 | 712 | */ | ||
868 | 713 | for (std::vector<RenderObject *>::const_iterator iter = windows.begin(); | ||
869 | 714 | iter != windows.end(); | ||
870 | 715 | iter++) | ||
871 | 716 | { | ||
872 | 717 | bool should_update = true; | ||
873 | 718 | RenderObject *win = *iter; | ||
874 | 719 | LibMatrix::vec2 new_pos( | ||
875 | 720 | win->position().x() + win->speed().x() * dt, | ||
876 | 721 | win->position().y() + win->speed().y() * dt); | ||
877 | 722 | |||
878 | 723 | if (new_pos.x() < 0.0 || | ||
879 | 724 | new_pos.x() + win->size().x() > ((float)mCanvas.width())) | ||
880 | 725 | { | ||
881 | 726 | win->speed(LibMatrix::vec2(-win->speed().x(), win->speed().y())); | ||
882 | 727 | should_update = false; | ||
883 | 728 | } | ||
884 | 729 | |||
885 | 730 | if (new_pos.y() < 0.0 || | ||
886 | 731 | new_pos.y() + win->size().y() > ((float)mCanvas.height())) | ||
887 | 732 | { | ||
888 | 733 | win->speed(LibMatrix::vec2(win->speed().x(), -win->speed().y())); | ||
889 | 734 | should_update = false; | ||
890 | 735 | } | ||
891 | 736 | |||
892 | 737 | if (should_update) | ||
893 | 738 | win->position(new_pos); | ||
894 | 739 | } | ||
895 | 740 | |||
896 | 741 | if (elapsed_time >= mDuration) { | ||
897 | 742 | mAverageFPS = mCurrentFrame / elapsed_time; | ||
898 | 743 | mRunning = false; | ||
899 | 744 | } | ||
900 | 745 | |||
901 | 746 | mCurrentFrame++; | ||
902 | 747 | } | ||
903 | 748 | |||
904 | 749 | void | ||
905 | 750 | SceneDesktop::draw() | ||
906 | 751 | { | ||
907 | 752 | std::vector<RenderObject *>& windows(priv_->windows); | ||
908 | 753 | |||
909 | 754 | /* Ensure we get a transparent clear color for all following operations */ | ||
910 | 755 | glClearColor(0.0, 0.0, 0.0, 0.0); | ||
911 | 756 | |||
912 | 757 | priv_->desktop.clear(); | ||
913 | 758 | |||
914 | 759 | for (std::vector<RenderObject *>::const_iterator iter = windows.begin(); | ||
915 | 760 | iter != windows.end(); | ||
916 | 761 | iter++) | ||
917 | 762 | { | ||
918 | 763 | RenderObject *win = *iter; | ||
919 | 764 | win->render_to(priv_->desktop); | ||
920 | 765 | } | ||
921 | 766 | |||
922 | 767 | priv_->desktop.render_to(priv_->screen); | ||
923 | 768 | |||
924 | 769 | } | ||
925 | 770 | |||
926 | 771 | Scene::ValidationResult | ||
927 | 772 | SceneDesktop::validate() | ||
928 | 773 | { | ||
929 | 774 | return ValidationUnknown; | ||
930 | 775 | } | ||
931 | 0 | 776 | ||
932 | === modified file 'src/scene.h' | |||
933 | --- src/scene.h 2011-08-18 13:20:04 +0000 | |||
934 | +++ src/scene.h 2011-09-13 09:41:05 +0000 | |||
935 | @@ -331,4 +331,23 @@ | |||
936 | 331 | void create_and_setup_mesh(); | 331 | void create_and_setup_mesh(); |
937 | 332 | }; | 332 | }; |
938 | 333 | 333 | ||
939 | 334 | struct SceneDesktopPrivate; | ||
940 | 335 | |||
941 | 336 | class SceneDesktop : public Scene | ||
942 | 337 | { | ||
943 | 338 | public: | ||
944 | 339 | SceneDesktop(Canvas &canvas); | ||
945 | 340 | int load(); | ||
946 | 341 | void unload(); | ||
947 | 342 | void setup(); | ||
948 | 343 | void teardown(); | ||
949 | 344 | void update(); | ||
950 | 345 | void draw(); | ||
951 | 346 | ValidationResult validate(); | ||
952 | 347 | |||
953 | 348 | ~SceneDesktop(); | ||
954 | 349 | |||
955 | 350 | private: | ||
956 | 351 | SceneDesktopPrivate *priv_; | ||
957 | 352 | }; | ||
958 | 334 | #endif | 353 | #endif |
Overall, looks really good. I like it. A few very small nits inline,
none of which should hold up the merge (and are all optional)...
On Mon, Sep 12, 2011 at 9:40 AM, Alexandros Frantzis <email address hidden> wrote: /code.launchpad .net/~linaro- graphics- wg/glmark2/ desktop/ +merge/ 75039 /code.launchpad .net/~linaro- graphics- wg/glmark2/ desktop/ +merge/ 75039 desktop- blur.frag' desktop- blur.frag 1970-01-01 00:00:00 +0000 desktop- blur.frag 2011-09-12 16:40:37 +0000 desktop. frag' desktop. frag 1970-01-01 00:00:00 +0000 desktop. frag 2011-09-12 16:40:37 +0000 MaterialTexture 0, TextureCoord); desktop. vert' desktop. vert 1970-01-01 00:00:00 +0000 desktop. vert 2011-09-12 16:40:37 +0000 desktop- window. png' desktop- window. png 1970-01-01 00:00:00 +0000 and data/textures/ desktop- window. png 2011-09-12 16:40:37 +0000 differ kernel= 0,1,0;1, -4,1;0, 1,0;", kernel= 1,1,1,1, 1;1,1,1, 1,1;1,1, 1,1,1;" , quads=5: texture= false:light= false", windows= 4:effect= blur:blur- radius= 5:passes= 1:separable= true", vertex- steps=0: fragment- steps=0" , vertex- steps=0: fragment- steps=5" , vertex- steps=5: fragment- steps=0" , :register_ scene(* new SceneBump( *g_canvas) ); :register_ scene(* new SceneEffect2D( *g_canvas) ); :register_ scene(* new ScenePulsar( *g_canvas) ); :register_ scene(* new SceneDesktop( canvas) ); benchmarks( g_benchmarks) ; android. cpp' android. cpp 2011-08-10 18:00:03 +0000
> Alexandros Frantzis has proposed merging lp:~linaro-graphics-wg/glmark2/desktop into lp:glmark2.
>
> Requested reviews:
> Jesse Barker (jesse-barker)
>
> For more details, see:
> https:/
>
> New "desktop" benchmarking scene and one effect (blur).
> --
> https:/
> You are requested to review the proposed merge of lp:~linaro-graphics-wg/glmark2/desktop into lp:glmark2.
>
> === added file 'data/shaders/
> --- data/shaders/
> +++ data/shaders/
> @@ -0,0 +1,17 @@
> +#ifdef GL_ES
> +precision mediump float;
> +#endif
> +
> +uniform sampler2D Texture0;
> +
> +varying vec2 TextureCoord;
> +
> +void main(void)
> +{
> + vec4 result;
> +
> + $CONVOLUTION$
> +
> + gl_FragColor = result;
> +}
> +
>
> === added file 'data/shaders/
> --- data/shaders/
> +++ data/shaders/
> @@ -0,0 +1,14 @@
> +#ifdef GL_ES
> +precision mediump float;
> +#endif
> +
> +uniform sampler2D MaterialTexture0;
> +
> +varying vec2 TextureCoord;
> +
> +void main(void)
> +{
> + vec4 texel = texture2D(
> + gl_FragColor = texel;
> +}
> +
>
> === added file 'data/shaders/
> --- data/shaders/
> +++ data/shaders/
> @@ -0,0 +1,11 @@
> +attribute vec2 position;
> +attribute vec2 texcoord;
> +
> +varying vec2 TextureCoord;
> +
> +void main(void)
> +{
> + gl_Position = vec4(position, 0.0, 1.0);
> +
> + TextureCoord = texcoord;
> +}
>
> === added file 'data/textures/
> Binary files data/textures/
> === modified file 'src/android.cpp'
> --- src/android.cpp 2011-08-18 15:03:40 +0000
> +++ src/android.cpp 2011-09-12 16:40:37 +0000
> @@ -44,6 +44,7 @@
> "effect2d:
> "effect2d:
> "pulsar:
> + "desktop:
> "conditionals:
> "conditionals:
> "conditionals:
> @@ -85,6 +86,7 @@
> Benchmark:
> Benchmark:
> Benchmark:
> + Benchmark:
>
> add_default_
>
>
> === modified file 'src/canvas-
> --- src/canvas-
> +++ src/canv...