From e82baf2703a5988436decba5260f32e948e65fc2 Mon Sep 17 00:00:00 2001 From: Oleksandr Shcherbina Date: Wed, 2 Dec 2015 14:47:28 -0800 Subject: [PATCH] evas: set visible texcolorpick texture in 3D shaders Summary: Add uniform varialble uColorTexture. Generate sampler count for textcolorpick and pass to renderer for bind additional texture unit to gl. It can be used for different 3D effects - blur, wave distortion, heat haze, etc. T2761 Reviewers: Hermet, raster, cedric Reviewed By: cedric Differential Revision: https://phab.enlightenment.org/D3372 Signed-off-by: Cedric BAIL --- src/modules/evas/engines/gl_common/evas_gl_3d.c | 15 +++++++++++---- .../evas/engines/gl_common/evas_gl_3d_private.h | 5 ++++- .../evas/engines/gl_common/evas_gl_3d_renderer.c | 21 ++++++++++++++++++++- .../evas/engines/gl_common/evas_gl_3d_shader.c | 5 +++++ 4 files changed, 40 insertions(+), 6 deletions(-) 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 357039c..4cb6887 100644 --- a/src/modules/evas/engines/gl_common/evas_gl_3d.c +++ b/src/modules/evas/engines/gl_common/evas_gl_3d.c @@ -1122,13 +1122,19 @@ _mesh_draw_data_build(E3D_Draw_Data *data, _light_build(data, light, matrix_eye); eina_normal3_matrix_get(&data->matrix_normal, matrix_mv); } - - int num; + /*Check possible quantity of texture units*/ + int num, count = 0; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &num); data->smap_sampler = num - 1; - if (data->texture_count >= num) - if ((data->flags & E3D_SHADER_FLAG_SHADOWED) || (data->texture_count > num)) + if (data->render_to_texture) + { + count++; + data->colortex_sampler = num - (count + 1); + } + if (data->texture_count + count >= num) + if ((data->flags & E3D_SHADER_FLAG_SHADOWED) || + (data->texture_count + count > num)) { ERR("Too many textures for your graphics configuration."); return EINA_FALSE; @@ -1144,6 +1150,7 @@ _mesh_draw(E3D_Renderer *renderer, Evas_Canvas3D_Mesh *mesh, int frame, Evas_Can E3D_Draw_Data data; memset(&data, 0x00, sizeof(E3D_Draw_Data)); + data.render_to_texture = e3d_renderer_rendering_to_texture_get(renderer); if (_mesh_draw_data_build(&data, mesh, frame, matrix_eye, matrix_mv, matrix_mvp, matrix_light, light)) e3d_renderer_draw(renderer, &data); 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 56f98c1..9478093 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 @@ -87,6 +87,7 @@ struct _E3D_Draw_Data Evas_Real shininess; GLint smap_sampler; + GLint colortex_sampler; Evas_Canvas3D_Blend_Func blend_sfactor; Evas_Canvas3D_Blend_Func blend_dfactor; Eina_Bool blending : 1; @@ -111,6 +112,8 @@ struct _E3D_Draw_Data Evas_Real pcf_step; Evas_Real pcf_size; Evas_Real constant_bias; + + Eina_Bool render_to_texture; }; struct _E3D_Texture @@ -171,5 +174,5 @@ void e3d_renderer_clear(E3D_Renderer *renderer, const Evas_Color void e3d_renderer_draw(E3D_Renderer *renderer, E3D_Draw_Data *data); void e3d_renderer_flush(E3D_Renderer *renderer); void e3d_renderer_color_pick_target_set(E3D_Renderer *renderer, E3D_Drawable *drawable); - +Eina_Bool e3d_renderer_rendering_to_texture_get(E3D_Renderer *renderer); #endif /* EVAS_GL_3D_PRIVATE_H */ 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 aff604c..05e6e97 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 @@ -15,7 +15,10 @@ struct _E3D_Renderer Eina_Bool vertex_attrib_enable[E3D_MAX_VERTEX_ATTRIB_COUNT]; Eina_Bool depth_test_enable; GLuint texDepth; - GLint smap_sampler; + GLint smap_sampler; + Eina_Bool render_to_texture; + GLuint texcolorpick; + GLint colortex_sampler; }; static inline GLenum @@ -208,6 +211,12 @@ _renderer_texture_bind(E3D_Renderer *renderer, E3D_Draw_Data *data) glBindTexture(GL_TEXTURE_2D, renderer->texDepth); renderer->smap_sampler = data->smap_sampler; } + if (renderer->render_to_texture) + { + glActiveTexture(GL_TEXTURE0 + data->colortex_sampler); + glBindTexture(GL_TEXTURE_2D, renderer->texcolorpick); + renderer->colortex_sampler = data->colortex_sampler; + } } static inline void @@ -269,6 +278,8 @@ e3d_renderer_target_set(E3D_Renderer *renderer, E3D_Drawable *target) glViewport(0, 0, target->w, target->h); renderer->fbo = target->fbo; renderer->texDepth = target->texDepth; + renderer->texcolorpick = target->texcolorpick; + renderer->render_to_texture = EINA_FALSE; } void @@ -288,6 +299,14 @@ e3d_renderer_color_pick_target_set(E3D_Renderer *renderer, E3D_Drawable *drawabl #endif glViewport(0, 0, drawable->w, drawable->h); renderer->texDepth = drawable->texDepth; + renderer->texcolorpick = drawable->texcolorpick; + renderer->render_to_texture = EINA_TRUE; +} + +Eina_Bool +e3d_renderer_rendering_to_texture_get(E3D_Renderer *renderer) +{ + return renderer->render_to_texture; } void 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 c013762..9fca4a1 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 @@ -68,6 +68,7 @@ typedef enum _E3D_Uniform E3D_UNIFORM_COLOR_PICK, E3D_UNIFORM_ALPHATEST_COMPARISON, E3D_UNIFORM_ALPHATEST_REFVALUE, + E3D_UNIFORM_RENDER_TO_TEXTURE, E3D_UNIFORM_COUNT, } E3D_Uniform; @@ -361,6 +362,7 @@ static const char *uniform_names[] = "uColorPick", "uAlphaTestComparison", "uAlphaTestRefValue", + "uColorTexture", }; static inline void @@ -630,6 +632,9 @@ _uniform_upload(E3D_Uniform u, GLint loc, const E3D_Draw_Data *data) case E3D_UNIFORM_ALPHATEST_REFVALUE: glUniform1f(loc, (data->alpha_ref_value ? data->alpha_ref_value : 0.0)); break; + case E3D_UNIFORM_RENDER_TO_TEXTURE: + glUniform1i(loc, data->colortex_sampler); + break; default: ERR("Invalid uniform ID."); break; -- 2.7.4