Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Evas : Use server based buffers for vertices instead of client buffers

Implement a auto-free system of the allocated buffers to avoid using
resources that we may not need anymore.
  • Loading branch information...
commit d62f360acc9a9b3274e8aeaf2032bf6c9d974f15 1 parent 64aabd7
@kakaroto authored
View
8 evas/src/modules/engines/gl_common/evas_gl_common.h
@@ -274,6 +274,9 @@ struct _Evas_GL_Shared
#define RTYPE_IMASK 6
#define RTYPE_YUY2 7
#define RTYPE_NV12 8
+#define GL_USE_SERVER_BUFFERS
+#define ARRAY_BUFFER_USE 500
+#define ARRAY_BUFFER_USE_SHIFT 100
struct _Evas_Engine_GL_Context
{
@@ -336,6 +339,11 @@ struct _Evas_Engine_GL_Context
Eina_Bool use_texuv3 : 1;
Eina_Bool use_texm : 1;
Evas_GL_Image *im;
+#ifdef GL_USE_SERVER_BUFFERS
+ GLuint buffer;
+ int buffer_alloc;
+ int buffer_use;
+#endif
} array;
} pipe[MAX_PIPES];
View
75 evas/src/modules/engines/gl_common/evas_gl_context.c
@@ -511,7 +511,14 @@ evas_gl_common_context_new(void)
_evas_gl_common_context = gc;
for (i = 0; i < MAX_PIPES; i++)
- gc->pipe[i].shader.render_op = EVAS_RENDER_BLEND;
+ {
+ gc->pipe[i].shader.render_op = EVAS_RENDER_BLEND;
+#ifdef GL_USE_SERVER_BUFFERS
+ glGenBuffers (1, &gc->pipe[i].array.buffer);
+ gc->pipe[i].array.buffer_alloc = 0;
+ gc->pipe[i].array.buffer_use = 0;
+#endif
+ }
if (!shared)
{
@@ -771,6 +778,11 @@ evas_gl_common_context_free(Evas_Engine_GL_Context *gc)
if (gc->def_surface) evas_gl_common_image_free(gc->def_surface);
+#ifdef GL_USE_SERVER_BUFFERS
+ for (i = 0; i < MAX_PIPES; i++)
+ glDeleteBuffers (1, &gc->pipe[i].array.buffer);
+#endif
+
if (gc->shared)
{
for (i = 0; i < gc->shared->info.tune.pipes.max; i++)
@@ -2550,16 +2562,60 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
gc->pipe[i].shader.cw, gc->pipe[i].shader.ch);
}
}
+#ifdef GL_USE_SERVER_BUFFERS
+# define VERTEX_SIZE (gc->pipe[i].array.alloc * sizeof(GLshort) * 3)
+# define COLOR_SIZE (gc->pipe[i].array.alloc * sizeof(GLubyte) * 4)
+# define TEX_SIZE (gc->pipe[i].array.alloc * sizeof(GLfloat) * 2)
+# define VERTEX_POINTER 0
+# define COLOR_POINTER (VERTEX_POINTER + VERTEX_SIZE)
+# define TEXUV_POINTER (COLOR_POINTER + COLOR_SIZE)
+# define TEXUV2_POINTER (TEXUV_POINTER + TEX_SIZE)
+# define TEXUV3_POINTER (TEXUV2_POINTER + TEX_SIZE)
+# define TEXM_POINTER (TEXUV3_POINTER + TEX_SIZE)
+# define END_POINTER (TEXM_POINTER + TEX_SIZE)
+
+ glBindBuffer(GL_ARRAY_BUFFER, gc->pipe[i].array.buffer);
+
+ if (gc->pipe[i].array.buffer_alloc < END_POINTER ||
+ gc->pipe[i].array.buffer_use >= (ARRAY_BUFFER_USE + ARRAY_BUFFER_USE_SHIFT * i))
+ {
+ glBufferData(GL_ARRAY_BUFFER, END_POINTER, NULL, GL_STATIC_DRAW);
+ gc->pipe[i].array.buffer_alloc = END_POINTER;
+ gc->pipe[i].array.buffer_use = 0;
+ }
+ gc->pipe[i].array.buffer_use++;
- glVertexAttribPointer(SHAD_VERTEX, 3, GL_SHORT, GL_FALSE, 0, gc->pipe[i].array.vertex);
+ void * x = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
+ if (gc->pipe[i].array.use_vertex)
+ memcpy (x + VERTEX_POINTER, gc->pipe[i].array.vertex, VERTEX_SIZE);
+ if (gc->pipe[i].array.use_color)
+ memcpy (x + COLOR_POINTER, gc->pipe[i].array.color, COLOR_SIZE);
+ if (gc->pipe[i].array.use_texuv)
+ memcpy (x + TEXUV_POINTER, gc->pipe[i].array.texuv, TEX_SIZE);
+ if (gc->pipe[i].array.use_texuv2)
+ memcpy (x + TEXUV2_POINTER, gc->pipe[i].array.texuv2, TEX_SIZE);
+ if (gc->pipe[i].array.use_texuv3)
+ memcpy (x + TEXUV3_POINTER, gc->pipe[i].array.texuv3, TEX_SIZE);
+ if (gc->pipe[i].array.use_texm)
+ memcpy (x + TEXM_POINTER, gc->pipe[i].array.texm, TEX_SIZE);
+ glUnmapBuffer(GL_ARRAY_BUFFER);
+#else
+# define VERTEX_POINTER gc->pipe[i].array.vertex
+# define COLOR_POINTER gc->pipe[i].array.color
+# define TEXUV_POINTER gc->pipe[i].array.texuv
+# define TEXUV2_POINTER gc->pipe[i].array.texuv2
+# define TEXUV3_POINTER gc->pipe[i].array.texuv3
+# define TEXM_POINTER gc->pipe[i].array.texm
+#endif
+ glVertexAttribPointer(SHAD_VERTEX, 3, GL_SHORT, GL_FALSE, 0, VERTEX_POINTER);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
- glVertexAttribPointer(SHAD_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, gc->pipe[i].array.color);
+ glVertexAttribPointer(SHAD_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, COLOR_POINTER);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
if (gc->pipe[i].array.use_texuv)
{
glEnableVertexAttribArray(SHAD_TEXUV);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
- glVertexAttribPointer(SHAD_TEXUV, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv);
+ glVertexAttribPointer(SHAD_TEXUV, 2, GL_FLOAT, GL_FALSE, 0, TEXUV_POINTER);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
}
else
@@ -2585,7 +2641,7 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
{
glEnableVertexAttribArray(SHAD_TEXM);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
- glVertexAttribPointer(SHAD_TEXM, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texm);
+ glVertexAttribPointer(SHAD_TEXM, 2, GL_FLOAT, GL_FALSE, 0, TEXM_POINTER);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
glActiveTexture(GL_TEXTURE1);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
@@ -2604,9 +2660,9 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
glEnableVertexAttribArray(SHAD_TEXUV3);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
- glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv2);
+ glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, TEXUV2_POINTER);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
- glVertexAttribPointer(SHAD_TEXUV3, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv3);
+ glVertexAttribPointer(SHAD_TEXUV3, 2, GL_FLOAT, GL_FALSE, 0, TEXUV3_POINTER);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
glActiveTexture(GL_TEXTURE1);
@@ -2633,7 +2689,7 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
{
glEnableVertexAttribArray(SHAD_TEXUV2);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
- glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, gc->pipe[i].array.texuv2);
+ glVertexAttribPointer(SHAD_TEXUV2, 2, GL_FLOAT, GL_FALSE, 0, TEXUV2_POINTER);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
glActiveTexture(GL_TEXTURE1);
@@ -2711,6 +2767,9 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
gc->pipe[i].array.num = 0;
gc->pipe[i].array.alloc = 0;
+#ifdef GL_USE_SERVER_BUFFERS
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+#endif
gc->pipe[i].region.x = 0;
gc->pipe[i].region.y = 0;
gc->pipe[i].region.w = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.