summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmytro Dadyka <d.dadyka@samsung.com>2014-12-01 07:39:36 +0100
committerCedric BAIL <cedric@osg.samsung.com>2014-12-01 08:09:29 +0100
commit6762af0beb5f53e299a65bca38dcb0739dd6c6cc (patch)
tree7a88064f8bd519549dbbb89bf8853fcb8234e77d
parent30a44d91006ca7dbcce3f00b5ebd4192ebfa40ef (diff)
evas: Evas_3D - add mesh blending mode.
Reviewers: Hermet, raster, cedric Subscribers: Oleksander, cedric @feature Differential Revision: https://phab.enlightenment.org/D1548 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/examples/evas/Makefile.am5
-rw-r--r--src/examples/evas/evas-3d-blending.c396
-rw-r--r--src/lib/evas/Evas_Eo.h35
-rw-r--r--src/lib/evas/canvas/evas_3d_mesh.c32
-rw-r--r--src/lib/evas/canvas/evas_3d_mesh.eo44
-rw-r--r--src/lib/evas/include/evas_private.h4
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d.c3
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_private.h5
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c47
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_shader.c2
10 files changed, 570 insertions, 3 deletions
diff --git a/src/examples/evas/Makefile.am b/src/examples/evas/Makefile.am
index db5edce..0d99147 100644
--- a/src/examples/evas/Makefile.am
+++ b/src/examples/evas/Makefile.am
@@ -248,6 +248,11 @@ evas_3d_obj_SOURCES = evas-3d-obj.c
248evas_3d_obj_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@ 248evas_3d_obj_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
249evas_3d_obj_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS) 249evas_3d_obj_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
250 250
251EXTRA_PROGRAMS += evas_3d_blending
252evas_3d_blending_SOURCES = evas-3d-blending.c
253evas_3d_blending_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
254evas_3d_blending_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
255
251EXTRA_PROGRAMS += evas_gl 256EXTRA_PROGRAMS += evas_gl
252evas_gl_SOURCES = evas-gl.c 257evas_gl_SOURCES = evas-gl.c
253evas_gl_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@ 258evas_gl_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
diff --git a/src/examples/evas/evas-3d-blending.c b/src/examples/evas/evas-3d-blending.c
new file mode 100644
index 0000000..86d78b6
--- /dev/null
+++ b/src/examples/evas/evas-3d-blending.c
@@ -0,0 +1,396 @@
1/**
2 * Example illustrating usage of blending modes. Press "Up" or "Down" key for change source blending factor.
3 * Press "Left" or "Right" for change destination blending factors.
4 * For more detailes see https://www.opengl.org/sdk/docs/man2/xhtml/glBlendFunc.xml
5 *
6 * @verbatim
7 * gcc -o evas-3d-blending evas-3d-blending.c `pkg-config --libs --cflags evas ecore ecore-evas eo`-lm
8 * @endverbatim
9 */
10
11#define EFL_EO_API_SUPPORT
12#define EFL_BETA_API_SUPPORT
13
14#include <math.h>
15#include <Eo.h>
16#include <Evas.h>
17#include <Ecore.h>
18#include <Ecore_Evas.h>
19
20#define WIDTH 1024
21#define HEIGHT 1024
22
23static const char *blend_func_names[] =
24{
25 /**< The scale factors for color components is (0, 0, 0, 0)*/
26 "EVAS_3D_BLEND_ZERO",
27 /**< The scale factors for color components is (1, 1, 1, 1)*/
28 "EVAS_3D_BLEND_ONE",
29 /**< The scale factors for color components is (Rs/kR, Gs/kG, Bs/kB, As/kA)*/
30 "EVAS_3D_BLEND_SRC_COLOR",
31 /**< The scale factors for color components is (1, 1, 1, 1) - (Rs/kR, Gs/kG, Bs/kB, As/kA)*/
32 "EVAS_3D_BLEND_ONE_MINUS_SRC_COLOR",
33 /**< The scale factors for color components is (Rd/kR, Gd/kG, Bd/kB, Ad/kA)*/
34 "EVAS_3D_BLEND_DST_COLOR",
35 /**< The scale factors for color components is (1, 1, 1, 1) - (Rd/kR, Gd/kG, Bd/kB, Ad/kA)*/
36 "EVAS_3D_BLEND_ONE_MINUS_DST_COLOR",
37 /**< The scale factors for color components is (As/kA, As/kA, As/kA, As/kA)*/
38 "EVAS_3D_BLEND_SRC_ALPHA",
39 /**< The scale factors for color components is (1, 1, 1, 1) - (As/kA, As/kA, As/kA, As/kA)*/
40 "EVAS_3D_BLEND_ONE_MINUS_SRC_ALPHA",
41 /**< The scale factors for color components is (Ad/kA, Ad/kA, Ad/kA, Ad/kA)*/
42 "EVAS_3D_BLEND_DST_ALPHA",
43 /**< The scale factors for color components is (1, 1, 1, 1) - (Ad/kA, Ad/kA, Ad/kA, Ad/kA)*/
44 "EVAS_3D_BLEND_ONE_MINUS_DST_ALPHA",
45 /**< The scale factors for color components is (Rc, Gc, Bc, Ac)*/
46 "EVAS_3D_BLEND_CONSTANT_COLOR",
47 /**< The scale factors for color components is (1, 1, 1, 1) - (Rc, Gc, Bc, Ac)*/
48 "EVAS_3D_BLEND_ONE_MINUS_CONSTANT_COLOR",
49 /**< The scale factors for color components is (Ac, Ac, Ac, Ac)*/
50 "EVAS_3D_BLEND_CONSTANT_ALPHA",
51 /**< The scale factors for color components is (1, 1, 1, 1) - (Ac, Ac, Ac, Ac)*/
52 "EVAS_3D_BLEND_ONE_MINUS_CONSTANT_ALPHA",
53 /**< The scale factors for color components is (i, i, i, 1) where i = min(As, kA, Ad)/kA*/
54 "EVAS_3D_BLEND_SRC_ALPHA_SATURATE",
55};
56
57typedef struct _Scene_Data
58{
59 Eo *scene;
60 Eo *root_node;
61 Eo *camera_node;
62 Eo *light_node;
63 Eo *mesh_node;
64 Eo *mesh_node1;
65
66 Eo *camera;
67 Eo *light;
68 Eo *mesh;
69 Eo *mesh1;
70 Eo *material;
71 Eo *material1;
72} Scene_Data;
73
74typedef struct _vec3
75{
76 float x;
77 float y;
78 float z;
79} vec3;
80
81typedef struct _vec4
82{
83 float x;
84 float y;
85 float z;
86 float w;
87} vec4;
88
89Ecore_Evas *ecore_evas = NULL;
90Evas *evas = NULL;
91Eo *background = NULL;
92Eo *image = NULL;
93
94int func1 = EVAS_3D_BLEND_SRC_ALPHA;
95int func2 = EVAS_3D_BLEND_ONE_MINUS_SRC_ALPHA;
96
97static void
98_on_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info)
99{
100 Scene_Data *scene = (Scene_Data *)data;
101 Evas_Event_Key_Down *ev = event_info;
102 Eina_Bool frustum;
103 Evas_Real x, y, z;
104
105 if (!strcmp("Up", ev->key))
106 func1++;
107 if (!strcmp("Down", ev->key))
108 func1--;
109 if (!strcmp("Left", ev->key))
110 func2++;
111 if (!strcmp("Right", ev->key))
112 func2--;
113
114 if(func1 < EVAS_3D_BLEND_ZERO)
115 func1 = EVAS_3D_BLEND_SRC_ALPHA_SATURATE;
116 if(func1 > EVAS_3D_BLEND_SRC_ALPHA_SATURATE)
117 func1 = EVAS_3D_BLEND_ZERO;
118
119 if(func2 < EVAS_3D_BLEND_ZERO)
120 func2 = EVAS_3D_BLEND_SRC_ALPHA_SATURATE;
121 if(func2 > EVAS_3D_BLEND_SRC_ALPHA_SATURATE)
122 func2 = EVAS_3D_BLEND_ZERO;
123 eo_do(scene->mesh1, evas_3d_mesh_blending_func_set(func1, func2));
124 printf("sfactor = %s, dfactor = %s\n", blend_func_names[func1], blend_func_names[func2]);
125}
126
127
128static void
129_on_delete(Ecore_Evas *ee EINA_UNUSED)
130{
131 ecore_main_loop_quit();
132}
133
134static void
135_on_canvas_resize(Ecore_Evas *ee)
136{
137 int w, h;
138
139 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
140
141 evas_object_resize(background, w, h);
142 eo_do(background, evas_obj_size_set(w, h));
143 eo_do(image, evas_obj_size_set(w, h));
144}
145
146static Eina_Bool
147_animate_scene(void *data)
148{
149 static float angle = 0.0f;
150 Scene_Data *scene = (Scene_Data *)data;
151
152 angle += 0.02;
153
154 eo_do(scene->mesh_node,
155 evas_3d_node_position_set(3 * sin(angle), 0.0, 3 * cos(angle)));
156
157 if (angle > 2 * M_PI) angle = 0;
158
159 return EINA_TRUE;
160}
161
162static void
163_camera_setup(Scene_Data *data)
164{
165 data->camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
166
167 eo_do(data->camera,
168 evas_3d_camera_projection_perspective_set(60.0, 1.0, 2.0, 50.0));
169
170 data->camera_node =
171 eo_add(EVAS_3D_NODE_CLASS, evas,
172 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_CAMERA));
173
174 eo_do(data->camera_node,
175 evas_3d_node_camera_set(data->camera),
176 evas_3d_node_position_set(0.0, 0.0, 10.0),
177 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
178 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
179
180 eo_do(data->root_node, evas_3d_node_member_add(data->camera_node));
181}
182
183static void
184_light_setup(Scene_Data *data)
185{
186 data->light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
187 eo_do(data->light,
188 evas_3d_light_ambient_set(0.2, 0.2, 0.2, 1.0),
189 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
190 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0));
191
192 data->light_node =
193 eo_add(EVAS_3D_NODE_CLASS, evas,
194 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_LIGHT));
195 eo_do(data->light_node,
196 evas_3d_node_light_set(data->light),
197 evas_3d_node_position_set(0.0, 0.0, 10.0),
198 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
199 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
200 eo_do(data->root_node, evas_3d_node_member_add(data->light_node));
201}
202
203static void
204_set_ball(Eo *mesh, int p, Evas_3D_Material *material)
205{
206 int vcount, icount, vccount, i, j;
207 double dtheta, dfi, sinth, costh, fi, theta, sinfi, cosfi;
208 unsigned short *indices, *index;
209
210 icount = p * p * 6;
211 vccount = p + 1;
212 vcount = vccount * vccount;
213
214 dtheta = M_PI / p;
215 dfi = 2 * M_PI / p;
216
217 vec3 *vertices = malloc(sizeof(vec3) * vcount);
218 vec3 *normals = malloc(sizeof(vec3) * vcount);
219
220 for (j = 0; j < vccount; j++)
221 {
222 theta = j * dtheta;
223 sinth = sin(theta);
224 costh = cos(theta);
225 for (i = 0; i < vccount; i++)
226 {
227 fi = i * dfi;
228 sinfi = sin(fi);
229 cosfi = cos(fi);
230 vertices[i + j * vccount].x = sinth * cosfi;
231 vertices[i + j * vccount].y = sinth * sinfi;
232 vertices[i + j * vccount].z = costh;
233
234 normals[i + j * vccount].x = sinth * cosfi;
235 normals[i + j * vccount].y = sinth * sinfi;
236 normals[i + j * vccount].z = costh;
237 }
238 }
239
240 indices = malloc(sizeof(short) * icount);
241 index = &indices[0];
242
243 for(j = 0; j < p; j++)
244 for(i = 0; i < p; i++)
245 {
246 *index++ = (unsigned short)(i + vccount * j);
247 *index++ = i + vccount * (j + 1);
248 *index++ = i + 1 + vccount * (j + 1);
249
250 *index++ = i + vccount * j;
251 *index++ = i + 1 + vccount * j;
252 *index++ = i + vccount * (j + 1) + 1;
253 }
254
255 eo_do(mesh, evas_3d_mesh_vertex_count_set(vcount),
256 evas_3d_mesh_frame_add(0);
257 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
258 sizeof(vec3), &vertices[0]);
259 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
260 sizeof(vec3), &normals[0]);
261 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
262 icount , &indices[0]);
263 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG);
264 evas_3d_mesh_frame_material_set(0, material));
265}
266
267static void
268_mesh_setup(Scene_Data *data)
269{
270 data->material = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
271
272 eo_do(data->material,
273 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
274 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
275 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
276
277 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 1.0, 0.2, 0.2, 0.2),
278 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 0.0, 0.0, 0.2),
279 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 0.2),
280 evas_3d_material_shininess_set(100.0));
281
282 data->material1 = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
283
284 eo_do(data->material1,
285 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
286 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
287 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
288
289 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.0, 0.2, 0.2, 0.2),
290 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.0, 0.0, 1.0, 0.2),
291 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 0.2),
292 evas_3d_material_shininess_set(100.0));
293
294 data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas);
295 data->mesh1 = eo_add(EVAS_3D_MESH_CLASS, evas);
296
297 _set_ball(data->mesh, 100, data->material);
298 _set_ball(data->mesh1, 100, data->material1);
299
300 data->mesh_node =
301 eo_add(EVAS_3D_NODE_CLASS, evas,
302 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
303
304 eo_do(data->root_node, evas_3d_node_member_add(data->mesh_node));
305 eo_do(data->mesh_node, evas_3d_node_mesh_add(data->mesh));
306
307 data->mesh_node1 =
308 eo_add(EVAS_3D_NODE_CLASS, evas,
309 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
310
311 eo_do(data->root_node, evas_3d_node_member_add(data->mesh_node1));
312 eo_do(data->mesh_node1, evas_3d_node_mesh_add(data->mesh1));
313
314 eo_do(data->mesh1, evas_3d_mesh_blending_enable_set(EINA_TRUE),
315 evas_3d_mesh_blending_func_set(func1, func2));
316
317 eo_do(data->mesh_node1,
318 evas_3d_node_scale_set(2.5, 2.5, 2.5));
319}
320
321static void
322_scene_setup(Scene_Data *data)
323{
324 data->scene = eo_add(EVAS_3D_SCENE_CLASS, evas);
325
326 eo_do(data->scene,
327 evas_3d_scene_size_set(WIDTH, HEIGHT);
328 evas_3d_scene_background_color_set(0.5, 0.5, 0.5, 1));
329
330 data->root_node =
331 eo_add(EVAS_3D_NODE_CLASS, evas,
332 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE));
333
334 _camera_setup(data);
335 _light_setup(data);
336 _mesh_setup(data);
337
338 eo_do(data->scene,
339 evas_3d_scene_root_node_set(data->root_node),
340 evas_3d_scene_camera_node_set(data->camera_node));
341}
342
343int
344main(void)
345{
346 Scene_Data data;
347 Ecore_Animator *anim;
348 Ecore_Evas *ecore_evas = NULL;
349
350 if (!ecore_evas_init()) return 0;
351
352 setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
353 ecore_evas = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
354
355 if (!ecore_evas) return 0;
356
357 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
358 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
359 ecore_evas_show(ecore_evas);
360
361 evas = ecore_evas_get(ecore_evas);
362
363 _scene_setup(&data);
364
365 /* Add a background rectangle objects. */
366 background = evas_object_rectangle_add(evas);
367 evas_object_color_set(background, 0, 0, 0, 255);
368 evas_object_move(background, 0, 0);
369 evas_object_resize(background, WIDTH, HEIGHT);
370 evas_object_show(background);
371
372 /* Add an image object for 3D scene rendering. */
373 image = evas_object_image_filled_add(evas);
374 evas_object_move(image, 0, 0);
375 evas_object_resize(image, WIDTH, HEIGHT);
376 evas_object_show(image);
377 evas_object_focus_set(image, EINA_TRUE);
378
379 /* Set the image object as render target for 3D scene. */
380 eo_do(image, evas_obj_image_scene_set(data.scene));
381
382
383 /* Add animation timer callback. */
384 ecore_animator_frametime_set(0.008);
385 anim = ecore_animator_add(_animate_scene, &data);
386
387 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_key_down, &data);
388 /* Enter main loop. */
389 ecore_main_loop_begin();
390
391 ecore_evas_free(ecore_evas);
392 ecore_evas_shutdown();
393 ecore_animator_del(anim);
394
395 return 0;
396}
diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h
index 9d8e93f..d512ced 100644
--- a/src/lib/evas/Evas_Eo.h
+++ b/src/lib/evas/Evas_Eo.h
@@ -486,6 +486,7 @@ typedef enum _Evas_3D_State
486 EVAS_3D_STATE_MESH_VERTEX_ASSEMBLY, 486 EVAS_3D_STATE_MESH_VERTEX_ASSEMBLY,
487 EVAS_3D_STATE_MESH_SHADE_MODE, 487 EVAS_3D_STATE_MESH_SHADE_MODE,
488 EVAS_3D_STATE_MESH_FOG, 488 EVAS_3D_STATE_MESH_FOG,
489 EVAS_3D_STATE_MESH_BLENDING,
489 490
490 EVAS_3D_STATE_CAMERA_PROJECTION = 1, 491 EVAS_3D_STATE_CAMERA_PROJECTION = 1,
491 492
@@ -606,6 +607,40 @@ typedef enum _Evas_3D_Vertex_Assembly
606 EVAS_3D_VERTEX_ASSEMBLY_TRIANGLE_FAN, 607 EVAS_3D_VERTEX_ASSEMBLY_TRIANGLE_FAN,
607} Evas_3D_Vertex_Assembly; 608} Evas_3D_Vertex_Assembly;
608 609
610typedef enum _Evas_3D_Blend_Func
611{
612 /**< The scale factors for color components is (0, 0, 0, 0)*/
613 EVAS_3D_BLEND_ZERO = 0,
614 /**< The scale factors for color components is (1, 1, 1, 1)*/
615 EVAS_3D_BLEND_ONE,
616 /**< The scale factors for color components is (Rs/kR, Gs/kG, Bs/kB, As/kA)*/
617 EVAS_3D_BLEND_SRC_COLOR,
618 /**< The scale factors for color components is (1, 1, 1, 1) - (Rs/kR, Gs/kG, Bs/kB, As/kA)*/
619 EVAS_3D_BLEND_ONE_MINUS_SRC_COLOR,
620 /**< The scale factors for color components is (Rd/kR, Gd/kG, Bd/kB, Ad/kA)*/
621 EVAS_3D_BLEND_DST_COLOR,
622 /**< The scale factors for color components is (1, 1, 1, 1) - (Rd/kR, Gd/kG, Bd/kB, Ad/kA)*/
623 EVAS_3D_BLEND_ONE_MINUS_DST_COLOR,
624 /**< The scale factors for color components is (As/kA, As/kA, As/kA, As/kA)*/
625 EVAS_3D_BLEND_SRC_ALPHA,
626 /**< The scale factors for color components is (1, 1, 1, 1) - (As/kA, As/kA, As/kA, As/kA)*/
627 EVAS_3D_BLEND_ONE_MINUS_SRC_ALPHA,
628 /**< The scale factors for color components is (Ad/kA, Ad/kA, Ad/kA, Ad/kA)*/
629 EVAS_3D_BLEND_DST_ALPHA,
630 /**< The scale factors for color components is (1, 1, 1, 1) - (Ad/kA, Ad/kA, Ad/kA, Ad/kA)*/
631 EVAS_3D_BLEND_ONE_MINUS_DST_ALPHA,
632 /**< The scale factors for color components is (Rc, Gc, Bc, Ac)*/
633 EVAS_3D_BLEND_CONSTANT_COLOR,
634 /**< The scale factors for color components is (1, 1, 1, 1) - (Rc, Gc, Bc, Ac)*/
635 EVAS_3D_BLEND_ONE_MINUS_CONSTANT_COLOR,
636 /**< The scale factors for color components is (Ac, Ac, Ac, Ac)*/
637 EVAS_3D_BLEND_CONSTANT_ALPHA,
638 /**< The scale factors for color components is (1, 1, 1, 1) - (Ac, Ac, Ac, Ac)*/
639 EVAS_3D_BLEND_ONE_MINUS_CONSTANT_ALPHA,
640 /**< The scale factors for color components is (i, i, i, 1) where i = min(As, kA, Ad)/kA*/
641 EVAS_3D_BLEND_SRC_ALPHA_SATURATE,
642} Evas_3D_Blend_Func;
643
609/** 644/**
610 * Color formats of pixel data 645 * Color formats of pixel data
611 * 646 *
diff --git a/src/lib/evas/canvas/evas_3d_mesh.c b/src/lib/evas/canvas/evas_3d_mesh.c
index f72d959..81b9117 100644
--- a/src/lib/evas/canvas/evas_3d_mesh.c
+++ b/src/lib/evas/canvas/evas_3d_mesh.c
@@ -117,6 +117,9 @@ _mesh_init(Evas_3D_Mesh_Data *pd)
117 pd->assembly = EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES; 117 pd->assembly = EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES;
118 118
119 pd->nodes = NULL; 119 pd->nodes = NULL;
120 pd->blend_sfactor = EVAS_3D_BLEND_ONE;
121 pd->blend_dfactor = EVAS_3D_BLEND_ZERO;
122 pd->blending = EINA_FALSE;
120} 123}
121 124
122static inline void 125static inline void
@@ -770,6 +773,35 @@ _evas_3d_mesh_fog_enable_get(Eo *obj EINA_UNUSED, Evas_3D_Mesh_Data *pd)
770} 773}
771 774
772EOLIAN static void 775EOLIAN static void
776_evas_3d_mesh_blending_enable_set(Eo *obj, Evas_3D_Mesh_Data *pd, Eina_Bool blending)
777{
778 pd->blending = blending;
779 eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_MESH_BLENDING, NULL));
780}
781
782EOLIAN static Eina_Bool
783_evas_3d_mesh_blending_enable_get(Eo *obj EINA_UNUSED, Evas_3D_Mesh_Data *pd)
784{
785 return pd->blending;
786}
787
788EOLIAN static void
789_evas_3d_mesh_blending_func_set(Eo *obj, Evas_3D_Mesh_Data *pd, Evas_3D_Blend_Func sfactor, Evas_3D_Blend_Func dfactor)
790{
791 pd->blend_sfactor = sfactor;
792 pd->blend_dfactor = dfactor;
793 eo_do(obj, evas_3d_object_change(EVAS_3D_STATE_MESH_BLENDING, NULL));
794}
795
796EOLIAN static void
797_evas_3d_mesh_blending_func_get(Eo *obj EINA_UNUSED, Evas_3D_Mesh_Data *pd,
798 Evas_3D_Blend_Func *sfactor, Evas_3D_Blend_Func *dfactor)
799{
800 if (sfactor) *sfactor = pd->blend_sfactor;
801 if (dfactor) *dfactor = pd->blend_dfactor;
802}
803
804EOLIAN static void
773_evas_3d_mesh_file_set(Eo *obj, Evas_3D_Mesh_Data *pd, Evas_3D_Mesh_File_Type type, const char *file, const char *key EINA_UNUSED) 805_evas_3d_mesh_file_set(Eo *obj, Evas_3D_Mesh_Data *pd, Evas_3D_Mesh_File_Type type, const char *file, const char *key EINA_UNUSED)
774{ 806{
775 _mesh_fini(pd); 807 _mesh_fini(pd);
diff --git a/src/lib/evas/canvas/evas_3d_mesh.eo b/src/lib/evas/canvas/evas_3d_mesh.eo
index 66d4f69..0fdf1a2 100644
--- a/src/lib/evas/canvas/evas_3d_mesh.eo
+++ b/src/lib/evas/canvas/evas_3d_mesh.eo
@@ -330,6 +330,27 @@ class Evas_3D_Mesh (Evas_3D_Object, Evas.Common_Interface)
330 @out Evas_Real a; /*@ Pointer to receive transparency of fog.*/ 330 @out Evas_Real a; /*@ Pointer to receive transparency of fog.*/
331 } 331 }
332 } 332 }
333 blending_func_set {
334 /*
335 Set the blending function for given mesh
336 @ingroup Evas_3D_Mesh
337 */
338 params {
339 @in Evas_3D_Blend_Func sfactor; /*@ Specifies how the red, green, blue, and alpha source blending factors are computed.*/
340 @in Evas_3D_Blend_Func dfactor; /*@ Specifies how the red, green, blue, and alpha destination blending factors are computed.*/
341 }
342 }
343 blending_func_get {
344 /*
345 Get blending blending function for given mesh
346 @see eavs_3d_mesh_blending_func_set()
347 @ingroup Evas_3D_Mesh
348 */
349 params {
350 @out Evas_3D_Blend_Func sfactor; /*@ Pointer to receive source blendin factors key.*/
351 @out Evas_3D_Blend_Func dfactor; /*@ Pointer to receive destination blendin factors key.*/
352 }
353 }
333 fog_enable_set { 354 fog_enable_set {
334 /* 355 /*
335 Enable or disable fog effect for given mesh. 356 Enable or disable fog effect for given mesh.
@@ -373,6 +394,29 @@ class Evas_3D_Mesh (Evas_3D_Object, Evas.Common_Interface)
373 Evas_3D_Shade_Mode mode; /*@ The shade mode.*/ 394 Evas_3D_Shade_Mode mode; /*@ The shade mode.*/
374 } 395 }
375 } 396 }
397 blending_enable {
398 set {
399 /**
400 * Enable or disable blending for given mesh.
401 *
402 * Default blending disabled.
403 *
404 * @ingroup Evas_3D_Mesh
405 */
406 }
407 get {
408 /**
409 * Get blending enable status for given mesh.
410 *
411 * @see eavs_3d_mesh_blending_enable_set()
412 *
413 * @ingroup Evas_3D_Mesh
414 */
415 }
416 values {
417 Eina_Bool blending; /*@ The blending state.*/
418 }
419 }
376 420
377 frame_material { 421 frame_material {
378 set { 422 set {
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index 6cf5c06..4f057c9 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -333,6 +333,10 @@ struct _Evas_3D_Mesh
333 Eina_Hash *nodes; 333 Eina_Hash *nodes;
334 Eina_Bool shadowed; 334 Eina_Bool shadowed;
335 335
336 Eina_Bool blending :1;
337 Evas_3D_Blend_Func blend_sfactor;
338 Evas_3D_Blend_Func blend_dfactor;
339
336 Evas_Color fog_color; 340 Evas_Color fog_color;
337 Eina_Bool fog_enabled :1; 341 Eina_Bool fog_enabled :1;
338}; 342};
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d.c b/src/modules/evas/engines/gl_common/evas_gl_3d.c
index e061c52..fea918e 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d.c
@@ -1103,6 +1103,9 @@ _mesh_draw_data_build(E3D_Draw_Data *data,
1103 if (pdmesh->shadowed) 1103 if (pdmesh->shadowed)
1104 data->flags |= E3D_SHADER_FLAG_SHADOWED; 1104 data->flags |= E3D_SHADER_FLAG_SHADOWED;
1105 1105
1106 data->blending = pdmesh->blending;
1107 data->blend_sfactor = pdmesh->blend_sfactor;
1108 data->blend_dfactor = pdmesh->blend_dfactor;
1106 data->mode = pdmesh->shade_mode; 1109 data->mode = pdmesh->shade_mode;
1107 data->assembly = pdmesh->assembly; 1110 data->assembly = pdmesh->assembly;
1108 data->vertex_count = pdmesh->vertex_count; 1111 data->vertex_count = pdmesh->vertex_count;
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d_private.h b/src/modules/evas/engines/gl_common/evas_gl_3d_private.h
index bc7fb93..75a76ac 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d_private.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d_private.h
@@ -84,7 +84,10 @@ struct _E3D_Draw_Data
84 84
85 Evas_Real shininess; 85 Evas_Real shininess;
86 86
87 GLint smap_sampler; 87 GLint smap_sampler;
88 Evas_3D_Blend_Func blend_sfactor;
89 Evas_3D_Blend_Func blend_dfactor;
90 Eina_Bool blending : 1;
88 91
89 struct { 92 struct {
90 Evas_Vec4 position; 93 Evas_Vec4 position;
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c b/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c
index 9c18f6f..82b0676 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c
@@ -41,6 +41,46 @@ _gl_assembly_get(Evas_3D_Vertex_Assembly assembly)
41 } 41 }
42} 42}
43 43
44static inline GLenum
45_gl_blend_func_get(Evas_3D_Blend_Func blend_func)
46{
47 switch (blend_func)
48 {
49 case EVAS_3D_BLEND_ZERO:
50 return GL_ZERO;
51 case EVAS_3D_BLEND_ONE:
52 return GL_ONE;
53 case EVAS_3D_BLEND_SRC_COLOR:
54 return GL_SRC_COLOR;
55 case EVAS_3D_BLEND_ONE_MINUS_SRC_COLOR:
56 return GL_ONE_MINUS_SRC_COLOR;
57 case EVAS_3D_BLEND_DST_COLOR:
58 return GL_DST_COLOR;
59 case EVAS_3D_BLEND_ONE_MINUS_DST_COLOR:
60 return GL_ONE_MINUS_DST_COLOR;
61 case EVAS_3D_BLEND_SRC_ALPHA:
62 return GL_SRC_ALPHA;
63 case EVAS_3D_BLEND_ONE_MINUS_SRC_ALPHA:
64 return GL_ONE_MINUS_SRC_ALPHA;
65 case EVAS_3D_BLEND_DST_ALPHA:
66 return GL_DST_ALPHA;
67 case EVAS_3D_BLEND_ONE_MINUS_DST_ALPHA:
68 return GL_ONE_MINUS_DST_ALPHA;
69 case EVAS_3D_BLEND_CONSTANT_COLOR:
70 return GL_CONSTANT_COLOR;
71 case EVAS_3D_BLEND_ONE_MINUS_CONSTANT_COLOR:
72 return GL_ONE_MINUS_CONSTANT_COLOR;
73 case EVAS_3D_BLEND_CONSTANT_ALPHA:
74 return GL_CONSTANT_ALPHA;
75 case EVAS_3D_BLEND_ONE_MINUS_CONSTANT_ALPHA:
76 return GL_ONE_MINUS_CONSTANT_ALPHA;
77 case EVAS_3D_BLEND_SRC_ALPHA_SATURATE:
78 return GL_SRC_ALPHA_SATURATE;
79 default:
80 return GL_ZERO;
81 }
82}
83
44static inline void 84static inline void
45_renderer_vertex_attrib_array_enable(E3D_Renderer *renderer, int index) 85_renderer_vertex_attrib_array_enable(E3D_Renderer *renderer, int index)
46{ 86{
@@ -271,6 +311,13 @@ e3d_renderer_draw(E3D_Renderer *renderer, E3D_Draw_Data *data)
271 while (index < E3D_MAX_VERTEX_ATTRIB_COUNT) 311 while (index < E3D_MAX_VERTEX_ATTRIB_COUNT)
272 _renderer_vertex_attrib_array_disable(renderer, index++); 312 _renderer_vertex_attrib_array_disable(renderer, index++);
273 313
314 if (data->blending)
315 {
316 glEnable(GL_BLEND);
317 glBlendFunc(_gl_blend_func_get(data->blend_sfactor), _gl_blend_func_get(data->blend_dfactor));
318 }
319 else glDisable(GL_BLEND);
320
274 if (data->indices) 321 if (data->indices)
275 { 322 {
276 _renderer_elements_draw(renderer, data->assembly, data->index_count, 323 _renderer_elements_draw(renderer, data->assembly, data->index_count,
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c b/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c
index 643ce6c..80401a6 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c
@@ -882,7 +882,6 @@ _fragment_shader_string_func_phong_add(E3D_Shader_String *shader,
882 ADD_LINE("gl_FragColor += color;"); 882 ADD_LINE("gl_FragColor += color;");
883 } 883 }
884 884
885 ADD_LINE("gl_FragColor.a = 1.0;");
886 ADD_LINE("}"); 885 ADD_LINE("}");
887} 886}
888 887
@@ -1055,7 +1054,6 @@ _fragment_shader_string_func_normal_map_add(E3D_Shader_String *shader,
1055 ADD_LINE("gl_FragColor += color;"); 1054 ADD_LINE("gl_FragColor += color;");
1056 } 1055 }
1057 1056
1058 ADD_LINE("gl_FragColor.a = 1.0;");
1059 ADD_LINE("}"); 1057 ADD_LINE("}");
1060} 1058}
1061 1059