summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-10-15 16:02:02 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-10-15 16:20:53 +0900
commit7b401f34dac59e118286c02fa2260c92eead2310 (patch)
tree424340a6e98b18ae1b9bdafec63f2f944b47bb3c /src
parentf6fd05ff74df03ace98d9158bf38f8322cffaf53 (diff)
Evas GL: Add more tests
- glReadPixels - FBO test - PBuffer test (only GL engine) - surface formats test (up to depth=24, stencil=8)
Diffstat (limited to 'src')
-rw-r--r--src/tests/evas/evas_test_evasgl.c304
1 files changed, 281 insertions, 23 deletions
diff --git a/src/tests/evas/evas_test_evasgl.c b/src/tests/evas/evas_test_evasgl.c
index 6ee7c92..cba2192 100644
--- a/src/tests/evas/evas_test_evasgl.c
+++ b/src/tests/evas/evas_test_evasgl.c
@@ -39,7 +39,8 @@ _detect_osmesa(void)
39 putenv("EVAS_GL_API_DEBUG=1"); \ 39 putenv("EVAS_GL_API_DEBUG=1"); \
40 evas_init(); \ 40 evas_init(); \
41 ecore_evas_init(); \ 41 ecore_evas_init(); \
42 ee = ecore_evas_new(engine, 0, 0, 1, 1, options); \ 42 if (!options || !strcmp(engine, "buffer")) ee = ecore_evas_new(engine, 0, 0, 1, 1, NULL); \
43 else ee = ecore_evas_gl_x11_options_new(NULL, NULL, 0, 0, 1, 1, options); \
43 if (!ee) { printf("Could not create ecore evas. Skipping Evas GL tests.\n"); \ 44 if (!ee) { printf("Could not create ecore evas. Skipping Evas GL tests.\n"); \
44 goto init_failed; } \ 45 goto init_failed; } \
45 ecore_evas_show(ee); \ 46 ecore_evas_show(ee); \
@@ -60,9 +61,9 @@ _detect_osmesa(void)
60 do {} while (0) 61 do {} while (0)
61 62
62static void 63static void
63_test_evasgl_init(const char *engine, const char *options) 64_test_evasgl_init(const char *engine)
64{ 65{
65 START_EVASGL_TEST(engine, options); 66 START_EVASGL_TEST(engine, NULL);
66 Evas_GL_Context *ctx; 67 Evas_GL_Context *ctx;
67 Evas_GL_Surface *sfc; 68 Evas_GL_Surface *sfc;
68 Evas_GL_Config *cfg; 69 Evas_GL_Config *cfg;
@@ -96,12 +97,9 @@ _test_evasgl_init(const char *engine, const char *options)
96} 97}
97 98
98static void 99static void
99_test_evasgl_current_get(const char *engine, const char *options) 100_test_evasgl_current_get(const char *engine)
100{ 101{
101 if (!_detect_osmesa()) 102 START_EVASGL_TEST(engine, NULL);
102 return;
103
104 START_EVASGL_TEST(engine, options);
105 Evas_GL_Context *ctx, *ctx2; 103 Evas_GL_Context *ctx, *ctx2;
106 Evas_GL_Surface *sfc, *sfc2; 104 Evas_GL_Surface *sfc, *sfc2;
107 Evas_GL_Config *cfg; 105 Evas_GL_Config *cfg;
@@ -127,12 +125,16 @@ _test_evasgl_current_get(const char *engine, const char *options)
127 fail_if(evgl2 != evgl); 125 fail_if(evgl2 != evgl);
128 fail_if(sfc2 != sfc); 126 fail_if(sfc2 != sfc);
129 fail_if(ctx2 != ctx); 127 fail_if(ctx2 != ctx);
128 fail_if(evas_gl_current_surface_get(evgl) != sfc);
129 fail_if(evas_gl_current_context_get(evgl) != ctx);
130 130
131 fail_if(!evas_gl_make_current(evgl, NULL, NULL)); 131 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
132 evgl2 = evas_gl_current_evas_gl_get(&ctx2, &sfc2); 132 evgl2 = evas_gl_current_evas_gl_get(&ctx2, &sfc2);
133 fail_if(evgl2 != evgl); /* this should not reset current Evas GL */ 133 fail_if(evgl2 != evgl); /* this should not reset current Evas GL */
134 fail_if(sfc2 != NULL); 134 fail_if(sfc2 != NULL);
135 fail_if(ctx2 != NULL); 135 fail_if(ctx2 != NULL);
136 fail_if(evas_gl_current_surface_get(evgl));
137 fail_if(evas_gl_current_context_get(evgl));
136 138
137 evas_gl_context_destroy(evgl, ctx); 139 evas_gl_context_destroy(evgl, ctx);
138 evas_gl_surface_destroy(evgl, sfc); 140 evas_gl_surface_destroy(evgl, sfc);
@@ -141,12 +143,9 @@ _test_evasgl_current_get(const char *engine, const char *options)
141} 143}
142 144
143static void 145static void
144_test_evasgl_context_version(const char *engine, const char *options) 146_test_evasgl_context_version(const char *engine)
145{ 147{
146 if (!_detect_osmesa()) 148 START_EVASGL_TEST(engine, NULL);
147 return;
148
149 START_EVASGL_TEST(engine, options);
150 Evas_GL_Context *ctx, *ctx2; 149 Evas_GL_Context *ctx, *ctx2;
151 Evas_GL_Surface *sfc; 150 Evas_GL_Surface *sfc;
152 Evas_GL_Config *cfg; 151 Evas_GL_Config *cfg;
@@ -199,12 +198,9 @@ _test_evasgl_context_version(const char *engine, const char *options)
199} 198}
200 199
201static void 200static void
202_test_evasgl_surfaceless_context(const char *engine, const char *options) 201_test_evasgl_surfaceless_context(const char *engine)
203{ 202{
204 if (!_detect_osmesa()) 203 START_EVASGL_TEST(engine, NULL);
205 return;
206
207 START_EVASGL_TEST(engine, options);
208 Evas_GL_Context *ctx; 204 Evas_GL_Context *ctx;
209 Evas_GL_Surface *sfc; 205 Evas_GL_Surface *sfc;
210 Evas_GL_Config *cfg; 206 Evas_GL_Config *cfg;
@@ -215,40 +211,294 @@ _test_evasgl_surfaceless_context(const char *engine, const char *options)
215 fail_if(!(evgl = evas_gl_new(evas))); 211 fail_if(!(evgl = evas_gl_new(evas)));
216 fail_if(!(ctx = evas_gl_context_create(evgl, NULL))); 212 fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
217 213
218 // FIXME: evas_gl_string_query will fail before the first make_current 214 // FIXME: evas_gl_string_query will fail before the first make_current (GL)
219 fail_if(!(cfg = evas_gl_config_new())); 215 fail_if(!(cfg = evas_gl_config_new()));
220 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1))); 216 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
221 fail_if(!evas_gl_make_current(evgl, sfc, ctx)); 217 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
222 // FIXME 218 // FIXME
223 219
220 fail_if(!(gl = evas_gl_context_api_get(evgl, ctx)));
221
224 eexts = evas_gl_string_query(evgl, EVAS_GL_EXTENSIONS); 222 eexts = evas_gl_string_query(evgl, EVAS_GL_EXTENSIONS);
225 if (eexts && strstr(eexts, "EGL_KHR_surfaceless_context")) 223 if (eexts && strstr(eexts, "EGL_KHR_surfaceless_context"))
226 { 224 {
227 fail_if(!evas_gl_make_current(evgl, NULL, ctx)); 225 fail_if(!evas_gl_make_current(evgl, NULL, ctx));
228 fail_if(!(gl = evas_gl_context_api_get(evgl, ctx)));
229 fail_if(!gl->glGetString(GL_VERSION)); 226 fail_if(!gl->glGetString(GL_VERSION));
230 } 227 }
231 else printf("Surfaceless context not supported. Skipped.\n"); 228 else printf("Surfaceless context not supported. Skipped.\n");
232 229
233 fail_if(!evas_gl_make_current(evgl, NULL, NULL)); 230 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
234 evas_gl_context_destroy(evgl, ctx); 231 evas_gl_context_destroy(evgl, ctx);
232 evas_gl_surface_destroy(evgl, sfc);
233 evas_gl_config_free(cfg);
234 evas_gl_free(evgl);
235 END_EVASGL_TEST();
236}
237
238static void
239_test_evasgl_glreadpixels(const char *engine)
240{
241 /* simple test verifying surface render works as expected */
242
243 START_EVASGL_TEST(engine, NULL);
244 Evas_GL_Context *ctx;
245 Evas_GL_Surface *sfc;
246 Evas_GL_Config *cfg;
247 Evas_GL_API *gl;
248 Evas_GL *evgl;
249 unsigned int pixel;
250
251 fail_if(!(evgl = evas_gl_new(evas)));
252 fail_if(!(cfg = evas_gl_config_new()));
253 fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
254 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
255 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
256 fail_if(!(gl = evas_gl_context_api_get(evgl, ctx)));
257
258 gl->glClearColor(0, 1, 0, 1);
259 gl->glClear(GL_COLOR_BUFFER_BIT);
260 gl->glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
261 fail_if(gl->glGetError() != GL_NO_ERROR);
262 fail_if(pixel != 0xFF00FF00);
263
264 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
265 evas_gl_context_destroy(evgl, ctx);
266 evas_gl_surface_destroy(evgl, sfc);
267 evas_gl_config_free(cfg);
268 evas_gl_free(evgl);
269 END_EVASGL_TEST();
270}
271
272static void
273_test_evasgl_fbo(const char *engine)
274{
275 /* simple test verifying FBO render works as expected */
276
277 START_EVASGL_TEST(engine, NULL);
278 Evas_GL_Context *ctx;
279 Evas_GL_Surface *sfc;
280 Evas_GL_Config *cfg;
281 Evas_GL_API *gl;
282 Evas_GL *evgl;
283 unsigned int pixel;
284 GLuint fbo, tex, vtx, frg, prg, u;
285 GLint status;
286
287 static const char *vertex =
288 "precision mediump float;\n"
289 "attribute vec4 vertex;\n"
290 "void main()\n"
291 "{\n"
292 " gl_Position = vertex;\n"
293 "}\n";
294 static const char *fragment =
295 "precision mediump float;\n"
296 "uniform vec4 color;\n"
297 "void main()\n"
298 "{\n"
299 " gl_FragColor = color;\n"
300 "}\n";
301 static const GLfloat color[] = { 1, 0, 0, 1 };
302 static const GLfloat vertices[] = {
303 1.0, 1.0, 0.0,
304 -1.0, -1.0, 0.0,
305 1.0, -1.0, 0.0,
306 1.0, 1.0, 0.0,
307 -1.0, 1.0, 0.0,
308 -1.0, -1.0, 0.0
309 };
310
311 /* surface & context */
312 fail_if(!(evgl = evas_gl_new(evas)));
313 fail_if(!(cfg = evas_gl_config_new()));
314 cfg->color_format = EVAS_GL_RGBA_8888;
315 fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
316 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
317 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
318 fail_if(!(gl = evas_gl_context_api_get(evgl, ctx)));
319
320 /* generate fbo */
321 gl->glGenFramebuffers(1, &fbo);
322 gl->glGenTextures(1, &tex);
323 gl->glBindFramebuffer(GL_FRAMEBUFFER, fbo);
324 gl->glBindTexture(GL_TEXTURE_2D, tex);
325 gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
326 gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
327 gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
328 gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
329 gl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
330 gl->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
331 fail_if(gl->glGetError() != GL_NO_ERROR);
332
333 /* prepare program */
334 vtx = gl->glCreateShader(GL_VERTEX_SHADER);
335 gl->glShaderSource(vtx, 1, &vertex, NULL);
336 gl->glCompileShader(vtx);
337 gl->glGetShaderiv(vtx, GL_COMPILE_STATUS, &status);
338 fail_if((gl->glGetError() != GL_NO_ERROR) || !status);
339 frg = gl->glCreateShader(GL_FRAGMENT_SHADER);
340 gl->glShaderSource(frg, 1, &fragment, NULL);
341 gl->glCompileShader(frg);
342 gl->glGetShaderiv(frg, GL_COMPILE_STATUS, &status);
343 fail_if((gl->glGetError() != GL_NO_ERROR) || !status);
344 prg = gl->glCreateProgram();
345 gl->glAttachShader(prg, vtx);
346 gl->glAttachShader(prg, frg);
347 gl->glBindAttribLocation(prg, 0, "vertex");
348 gl->glLinkProgram(prg);
349 gl->glGetProgramiv(prg, GL_LINK_STATUS, &status);
350 fail_if((gl->glGetError() != GL_NO_ERROR) || !status);
351
352 /* clear */
353 gl->glClearColor(0, 0, 0, 0);
354 gl->glClear(GL_COLOR_BUFFER_BIT);
355 fail_if(gl->glGetError() != GL_NO_ERROR);
356
357 /* set parameters */
358 gl->glUseProgram(prg);
359 u = gl->glGetUniformLocation(prg, "color");
360 gl->glUniform4fv(u, 1, color);
361 gl->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
362 gl->glEnableVertexAttribArray(0);
363 fail_if(gl->glGetError() != GL_NO_ERROR);
364
365 /* draw */
366 gl->glDrawArrays(GL_TRIANGLES, 0, 6);
367 gl->glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
368 fail_if(gl->glGetError() != GL_NO_ERROR);
369 fail_if(pixel != 0xFF0000FF);
370
371 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
372 evas_gl_context_destroy(evgl, ctx);
373 evas_gl_surface_destroy(evgl, sfc);
374 evas_gl_config_free(cfg);
375 evas_gl_free(evgl);
376 END_EVASGL_TEST();
377}
378
379static void
380_test_evasgl_pbuffer(const char *engine)
381{
382 /* check support for PBuffer */
383
384 // FIXME: No SW engine support!
385 if (!strcmp(engine, "buffer"))
386 {
387 printf("PBuffer not supported (SW engine). Skipped.\n");
388 return;
389 }
390
391 START_EVASGL_TEST(engine, NULL);
392 Evas_GL_Context *ctx;
393 Evas_GL_Surface *sfc;
394 Evas_GL_Config *cfg;
395 Evas_GL_API *gl;
396 Evas_GL *evgl;
397 unsigned int pixel;
398
399 fail_if(!(evgl = evas_gl_new(evas)));
400 fail_if(!(cfg = evas_gl_config_new()));
401 cfg->color_format = EVAS_GL_RGBA_8888;
402 fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
403 fail_if(!(sfc = evas_gl_pbuffer_surface_create(evgl, cfg, 1, 1, NULL)));
404 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
405 fail_if(!(gl = evas_gl_context_api_get(evgl, ctx)));
406
407 /* clear */
408 gl->glClearColor(0, 1, 0, 1);
409 gl->glClear(GL_COLOR_BUFFER_BIT);
410 gl->glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
411 fail_if(gl->glGetError() != GL_NO_ERROR);
412 fail_if(pixel != 0xFF00FF00);
413
414 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
415 evas_gl_context_destroy(evgl, ctx);
416 evas_gl_surface_destroy(evgl, sfc);
417 evas_gl_config_free(cfg);
235 evas_gl_free(evgl); 418 evas_gl_free(evgl);
419 END_EVASGL_TEST();
420}
421
422static void
423_test_evasgl_formats(const char *engine)
424{
425 /* check that Evas GL always falls back to working surface configs */
426
427 const int options[] = { ECORE_EVAS_GL_X11_OPT_GL_DEPTH, 24,
428 ECORE_EVAS_GL_X11_OPT_GL_STENCIL, 8,
429 ECORE_EVAS_GL_X11_OPT_GL_MSAA, 4,
430 0 };
431 const int *opts = options;
236 432
433 START_EVASGL_TEST(engine, opts);
434 Evas_GL_Context *ctx;
435 Evas_GL_Surface *sfc;
436 Evas_GL_Config *cfg;
437 Evas_GL *evgl;
438
439 fail_if(!(evgl = evas_gl_new(evas)));
440 fail_if(!(cfg = evas_gl_config_new()));
441 fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
442
443 // don't test DEPTH_32 or STENCIL_16
444 for (Evas_GL_Color_Format fmt = EVAS_GL_RGB_888; fmt < EVAS_GL_NO_FBO; fmt++)
445 for (Evas_GL_Depth_Bits depth = EVAS_GL_DEPTH_NONE; depth <= EVAS_GL_DEPTH_BIT_24; depth++)
446 for (Evas_GL_Stencil_Bits stencil = EVAS_GL_STENCIL_NONE; stencil <= EVAS_GL_STENCIL_BIT_8; stencil++)
447 for (Evas_GL_Options_Bits opt = EVAS_GL_OPTIONS_NONE; opt <= 2; opt += 2)
448 for (Evas_GL_Multisample_Bits msaa = EVAS_GL_MULTISAMPLE_NONE; msaa <= EVAS_GL_MULTISAMPLE_HIGH; msaa++)
449 {
450 cfg->color_format = fmt;
451 cfg->depth_bits = depth;
452 cfg->stencil_bits = stencil;
453 cfg->options_bits = opt;
454 cfg->multisample_bits = msaa;
455 cfg->gles_version = EVAS_GL_GLES_2_X;
456 /*
457 fprintf(stderr, "Testing surface %d %d %d %d %d\n",
458 cfg->color_format, cfg->depth_bits, cfg->stencil_bits,
459 cfg->multisample_bits, cfg->options_bits);
460 */
461 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
462 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
463 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
464 evas_gl_surface_destroy(evgl, sfc);
465 }
466
467 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
468 evas_gl_context_destroy(evgl, ctx);
469 evas_gl_config_free(cfg);
470 evas_gl_free(evgl);
237 END_EVASGL_TEST(); 471 END_EVASGL_TEST();
238} 472}
239 473
240#define TEST_ADD(name) \ 474#define TEST_ADD_OPT(name, opt) \
241 START_TEST(evas ## name ## _opengl_x11) \ 475 START_TEST(evas ## name ## _opengl_x11) \
242 { name("opengl_x11", NULL); } \ 476 { name("opengl_x11"); } \
243 END_TEST \ 477 END_TEST \
244 START_TEST(evas ## name ## _buffer) \ 478 START_TEST(evas ## name ## _buffer) \
245 { name("buffer", NULL); } \ 479 { name("buffer"); } \
246 END_TEST 480 END_TEST
481#define TEST_ADD(name) TEST_ADD_OPT(name, NULL)
247 482
248TEST_ADD(_test_evasgl_init) 483TEST_ADD(_test_evasgl_init)
249TEST_ADD(_test_evasgl_current_get) 484TEST_ADD(_test_evasgl_current_get)
250TEST_ADD(_test_evasgl_context_version) 485TEST_ADD(_test_evasgl_context_version)
251TEST_ADD(_test_evasgl_surfaceless_context) 486TEST_ADD(_test_evasgl_surfaceless_context)
487TEST_ADD(_test_evasgl_glreadpixels)
488TEST_ADD(_test_evasgl_fbo)
489TEST_ADD(_test_evasgl_formats)
490TEST_ADD(_test_evasgl_pbuffer)
491
492/* APIs still to test:
493 *
494 * evas_gl_rotation_get
495 * evas_gl_surface_query
496 * evas_gl_error_get
497 * evas_gl_native_surface_get
498 * evas_gl_proc_address_get
499 *
500 * Most of these actually need support in SW engine to be improved.
501 */
252 502
253void evas_test_evasgl(TCase *tc) 503void evas_test_evasgl(TCase *tc)
254{ 504{
@@ -261,6 +511,10 @@ void evas_test_evasgl(TCase *tc)
261 TEST_ADD(_test_evasgl_current_get); 511 TEST_ADD(_test_evasgl_current_get);
262 TEST_ADD(_test_evasgl_context_version); 512 TEST_ADD(_test_evasgl_context_version);
263 TEST_ADD(_test_evasgl_surfaceless_context); 513 TEST_ADD(_test_evasgl_surfaceless_context);
514 TEST_ADD(_test_evasgl_glreadpixels);
515 TEST_ADD(_test_evasgl_fbo);
516 TEST_ADD(_test_evasgl_pbuffer);
517 TEST_ADD(_test_evasgl_formats);
264 } 518 }
265 519
266#undef TEST_ADD 520#undef TEST_ADD
@@ -270,4 +524,8 @@ void evas_test_evasgl(TCase *tc)
270 TEST_ADD(_test_evasgl_current_get); 524 TEST_ADD(_test_evasgl_current_get);
271 TEST_ADD(_test_evasgl_context_version); 525 TEST_ADD(_test_evasgl_context_version);
272 TEST_ADD(_test_evasgl_surfaceless_context); 526 TEST_ADD(_test_evasgl_surfaceless_context);
527 TEST_ADD(_test_evasgl_glreadpixels);
528 TEST_ADD(_test_evasgl_fbo);
529 TEST_ADD(_test_evasgl_pbuffer);
530 TEST_ADD(_test_evasgl_formats);
273} 531}