summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/evas_gl_3d_private.h
blob: 94780937cf84141e5c3d116c226325e6b778ae49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef EVAS_GL_3D_PRIVATE_H
#define EVAS_GL_3D_PRIVATE_H

#include "evas_gl_common.h"

typedef struct _E3D_Program   E3D_Program;
typedef struct _E3D_Draw_Data E3D_Draw_Data;
typedef unsigned long         E3D_Shader_Flag;

// NOTE: order here should be equal with flag names in file evas_gl_3d_shader.c
#define E3D_SHADER_FLAG_NORMALIZE_NORMALS       (1 << 0)
#define E3D_SHADER_FLAG_VERTEX_POSITION         (1 << 1)
#define E3D_SHADER_FLAG_VERTEX_POSITION_BLEND   (1 << 2)
#define E3D_SHADER_FLAG_VERTEX_NORMAL           (1 << 3)
#define E3D_SHADER_FLAG_VERTEX_NORMAL_BLEND     (1 << 4)
#define E3D_SHADER_FLAG_VERTEX_TANGENT          (1 << 5)
#define E3D_SHADER_FLAG_VERTEX_TANGENT_BLEND    (1 << 6)
#define E3D_SHADER_FLAG_VERTEX_COLOR            (1 << 7)
#define E3D_SHADER_FLAG_VERTEX_COLOR_BLEND      (1 << 8)
#define E3D_SHADER_FLAG_VERTEX_TEXCOORD         (1 << 9)
#define E3D_SHADER_FLAG_VERTEX_TEXCOORD_BLEND   (1 << 10)
#define E3D_SHADER_FLAG_LIGHT_DIRECTIONAL       (1 << 11)
#define E3D_SHADER_FLAG_LIGHT_SPOT              (1 << 12)
#define E3D_SHADER_FLAG_LIGHT_ATTENUATION       (1 << 13)
#define E3D_SHADER_FLAG_AMBIENT                 (1 << 14)
#define E3D_SHADER_FLAG_DIFFUSE                 (1 << 15)
#define E3D_SHADER_FLAG_SPECULAR                (1 << 16)
#define E3D_SHADER_FLAG_EMISSION                (1 << 17)
#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE         (1 << 18)
#define E3D_SHADER_FLAG_AMBIENT_TEXTURE         (1 << 19)
#define E3D_SHADER_FLAG_SPECULAR_TEXTURE        (1 << 20)
#define E3D_SHADER_FLAG_EMISSION_TEXTURE        (1 << 21)
#define E3D_SHADER_FLAG_NORMAL_TEXTURE          (1 << 22)
#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND   (1 << 23)
#define E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND   (1 << 24)
#define E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND  (1 << 25)
#define E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND  (1 << 26)
#define E3D_SHADER_FLAG_NORMAL_TEXTURE_BLEND    (1 << 27)
#define E3D_SHADER_FLAG_FOG_ENABLED             (1 << 28)
#define E3D_SHADER_FLAG_ALPHA_TEST_ENABLED      (1 << 29)
#define E3D_SHADER_FLAG_SHADOWED                (1 << 30)
#define E3D_SHADER_FLAG_COUNT                    31

static inline Eina_Bool
_flags_need_tex_coord(E3D_Shader_Flag flags)
{
   return (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE) ||
          (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE) ||
          (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE) ||
          (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE) ||
          (flags & E3D_SHADER_FLAG_NORMAL_TEXTURE);
}

struct _E3D_Draw_Data
{
   E3D_Shader_Flag      flags;
   Evas_Canvas3D_Shade_Mode   mode;

   Eina_Matrix4   matrix_mvp;
   Eina_Matrix4   matrix_mv;
   Eina_Matrix3   matrix_normal;
   Eina_Matrix4   matrix_light;

   struct {
        Evas_Canvas3D_Vertex_Buffer vertex0;
        Evas_Canvas3D_Vertex_Buffer vertex1;
        Evas_Real             weight;
   } vertices[EVAS_CANVAS3D_VERTEX_ATTRIB_COUNT];

   Evas_Canvas3D_Vertex_Assembly assembly;
   int                     vertex_count;
   int                     index_count;
   Evas_Canvas3D_Index_Format    index_format;
   const void             *indices;

   GLint       texture_count;

   struct {
        Evas_Color            color;
        GLint                 sampler0;
        GLint                 sampler1;
        E3D_Texture          *tex0;
        E3D_Texture          *tex1;
        Evas_Real             texture_weight;
   } materials[EVAS_CANVAS3D_MATERIAL_ATTRIB_COUNT];

   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;

   Evas_Canvas3D_Comparison      alpha_comparison;
   Evas_Real               alpha_ref_value;
   Eina_Bool               alpha_test_enabled :1;

   struct {
        Eina_Quaternion   position;
        Evas_Vec3   spot_dir;
        Evas_Real   spot_exp;
        Evas_Real   spot_cutoff_cos;
        Evas_Vec3   atten;
        Evas_Color  ambient;
        Evas_Color  diffuse;
        Evas_Color  specular;
   } light;
   Evas_Color fog_color;
   Evas_Color color_pick_key;
   /*Sets of the quality of shadow rendering*/
   Evas_Real               pcf_step;
   Evas_Real               pcf_size;
   Evas_Real               constant_bias;

   Eina_Bool               render_to_texture;
};

struct _E3D_Texture
{
   /*Offset for atlasses*/
   int               x, y;
   int               w, h;

   Evas_GL_Image     *surface;
   /*Tranformation matrix, use it for adjusting texture unit coordinates*/
   Eina_Matrix3         trans;

   GLuint            tex;

   Eina_Bool         wrap_dirty;
   GLenum            wrap_s;
   GLenum            wrap_t;

   Eina_Bool         filter_dirty;
   GLenum            filter_min;
   GLenum            filter_mag;
   /*Use atlas for generation texture unit, @EINA_TRUE by default*/
   Eina_Bool         atlas_enable;
};

struct _E3D_Drawable
{
   int      w, h;
   int      alpha;
   GLenum   format;
   GLenum   depth_format;
   GLenum   stencil_format;
   GLuint   tex;
   GLuint   fbo;
   GLuint   depth_stencil_buf;
   GLuint   depth_buf;
   GLuint   stencil_buf;
   GLuint   texDepth;
   GLuint texcolorpick;
   GLuint color_pick_fb_id;
};

/* Texture internal functions. */
void                 e3d_texture_param_update(E3D_Texture *texture);

/* Program */
E3D_Program         *e3d_program_new(Evas_Canvas3D_Shade_Mode mode, E3D_Shader_Flag flags);
void                 e3d_program_free(E3D_Program *program);
GLuint               e3d_program_id_get(const E3D_Program *program);
Evas_Canvas3D_Shade_Mode   e3d_program_shade_mode_get(const E3D_Program *program);
E3D_Shader_Flag      e3d_program_shader_flags_get(const E3D_Program *program);
void                 e3d_program_uniform_upload(E3D_Program *program, const E3D_Draw_Data *data);

/* Renderer */
void                 e3d_renderer_target_set(E3D_Renderer *renderer, E3D_Drawable *target);
void                 e3d_renderer_viewport_set(E3D_Renderer *renderer, int x, int y, int w, int h);
void                 e3d_renderer_clear(E3D_Renderer *renderer, const Evas_Color *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 */