summaryrefslogtreecommitdiff
path: root/navit/graphics/egl/graphics_egl.c
diff options
context:
space:
mode:
Diffstat (limited to 'navit/graphics/egl/graphics_egl.c')
-rw-r--r--navit/graphics/egl/graphics_egl.c185
1 files changed, 54 insertions, 131 deletions
diff --git a/navit/graphics/egl/graphics_egl.c b/navit/graphics/egl/graphics_egl.c
index 758528a37..f9c33c775 100644
--- a/navit/graphics/egl/graphics_egl.c
+++ b/navit/graphics/egl/graphics_egl.c
@@ -88,8 +88,7 @@ struct graphics_priv {
struct graphics_gc_priv *background_gc;
enum draw_mode_num mode;
GLuint program;
- GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location,
- texture_location;
+ GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location, texture_location;
struct callback_list *cbl;
struct font_freetype_methods freetype_methods;
struct navit *nav;
@@ -177,11 +176,10 @@ float area(const struct contour* contour) {
return A * .5f;
}
-int
-inside_triangle(float Ax, float Ay,
- float Bx, float By,
- float Cx, float Cy,
- float Px, float Py) {
+int inside_triangle(float Ax, float Ay,
+ float Bx, float By,
+ float Cx, float Cy,
+ float Px, float Py) {
float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
float cCROSSap, bCROSScp, aCROSSbp;
@@ -205,8 +203,7 @@ inside_triangle(float Ax, float Ay,
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
}
-int
-snip(const struct point* pnt,int u,int v,int w,int n,int *V) {
+int snip(const struct point* pnt,int u,int v,int w,int n,int *V) {
int p;
float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
@@ -234,8 +231,7 @@ snip(const struct point* pnt,int u,int v,int w,int n,int *V) {
return 1;
}
-int
-process_triangles(const struct contour* contour, struct contour* result) {
+int process_triangles(const struct contour* contour, struct contour* result) {
int v;
int contour_size = contour->count - 1;
int polygon_temp_size = contour_size * 80;
@@ -309,8 +305,7 @@ process_triangles(const struct contour* contour, struct contour* result) {
/*
* Destroys SDL/EGL context
*/
-static void
-sdl_egl_destroy(struct graphics_opengl_platform *egl) {
+static void sdl_egl_destroy(struct graphics_opengl_platform *egl) {
if (egl->eglwindow) {
SDL_GL_DeleteContext(egl->eglcontext);
SDL_DestroyWindow(egl->eglwindow);
@@ -322,16 +317,14 @@ sdl_egl_destroy(struct graphics_opengl_platform *egl) {
/*
* Swap EGL buffer
*/
-static void
-sdl_egl_swap_buffers(struct graphics_opengl_platform *egl) {
+static void sdl_egl_swap_buffers(struct graphics_opengl_platform *egl) {
SDL_GL_SwapWindow(egl->eglwindow);
}
/*
* Main graphic destroy
*/
-static void
-graphics_destroy(struct graphics_priv *gr) {
+static void graphics_destroy(struct graphics_priv *gr) {
/*FIXME graphics_destroy is never called */
gr->freetype_methods.destroy();
g_free(gr);
@@ -340,20 +333,16 @@ graphics_destroy(struct graphics_priv *gr) {
SDL_Quit();
}
-static void
-gc_destroy(struct graphics_gc_priv *gc) {
+static void gc_destroy(struct graphics_gc_priv *gc) {
g_free(gc);
gc = NULL;
}
-static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+static void gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
gc->linewidth = w;
}
-static void
-gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
- unsigned char *dash_list, int n) {
+static void gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset, unsigned char *dash_list, int n) {
int i;
const int cOpenglMaskBits = 16;
gc->dash_count = n;
@@ -408,16 +397,14 @@ gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
}
-static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
gc->fr = c->r / 65535.0;
gc->fg = c->g / 65535.0;
gc->fb = c->b / 65535.0;
gc->fa = c->a / 65535.0;
}
-static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
+static void gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
gc->br = c->r / 65535.0;
gc->bg = c->g / 65535.0;
gc->bb = c->b / 65535.0;
@@ -432,8 +419,7 @@ static struct graphics_gc_methods gc_methods = {
gc_set_background
};
-static struct graphics_gc_priv *
-gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1);
*meth = gc_methods;
@@ -444,9 +430,7 @@ gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
static struct graphics_image_priv image_error;
-static struct graphics_image_priv *
-image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h,
- struct point *hot, int rotation) {
+static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation) {
struct graphics_image_priv *gi;
/* FIXME: meth is not used yet.. so gi leaks. at least xpm is small */
@@ -467,8 +451,7 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
}
if (strlen(name) < 4) {
- g_hash_table_insert(hImageData, g_strdup(name),
- &image_error);
+ g_hash_table_insert(hImageData, g_strdup(name), &image_error);
return NULL;
}
@@ -484,9 +467,7 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
dbg(lvl_error,"image_new on '%s' failed: %s", name, IMG_GetError());
g_free(gi);
gi = NULL;
- g_hash_table_insert(hImageData,
- g_strdup(name),
- &image_error);
+ g_hash_table_insert(hImageData, g_strdup(name), &image_error);
return gi;
}
@@ -494,14 +475,12 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
return gi;
}
-static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv * gi) {
+static void image_free(struct graphics_priv *gr, struct graphics_image_priv * gi) {
// SDL_FreeSurface(gi->img);
// g_free(gi);
}
-static void
-set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+static void set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
GLfloat col[4];
col[0]=gc->fr;
col[1]=gc->fg;
@@ -510,8 +489,7 @@ set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
glUniform4fv(gr->color_location, 1, col);
}
-static void
-draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode) {
+static void draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode) {
int i;
GLf *x;//[count*2];
x = alloca(sizeof(GLf)*count*2);
@@ -524,8 +502,7 @@ draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode) {
glDrawArrays(mode, 0, count);
}
-static void
-draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h) {
+static void draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h) {
struct point pa[4];
pa[0]=pa[1]=pa[2]=pa[3]=*p;
pa[0].x+=w;
@@ -536,8 +513,7 @@ draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h) {
}
-static void
-draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data) {
+static void draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data) {
GLf x[8];
GLuint texture;
memset(x, 0, sizeof(x));
@@ -571,8 +547,7 @@ draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned
glDeleteTextures(1, &texture);
}
-inline void
-get_overlay_pos(struct graphics_priv *gr, struct point *point_out) {
+inline void get_overlay_pos(struct graphics_priv *gr, struct point *point_out) {
if (gr->parent == NULL) {
point_out->x = 0;
point_out->y = 0;
@@ -589,8 +564,7 @@ get_overlay_pos(struct graphics_priv *gr, struct point *point_out) {
}
}
-inline void
-draw_overlay(struct graphics_priv *gr) {
+inline void draw_overlay(struct graphics_priv *gr) {
struct point p_eff;
GLf x[8];
@@ -618,9 +592,7 @@ draw_overlay(struct graphics_priv *gr) {
glDisable(GL_BLEND);
}
-static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count) {
+static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
&& !gr->overlay_enabled)) {
@@ -636,9 +608,7 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
}
-static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count) {
+static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
int ok;
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
@@ -659,9 +629,7 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
}
}
-static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int w, int h) {
+static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
&& !gr->overlay_enabled)) {
@@ -672,10 +640,7 @@ draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
graphics_priv_root->dirty = 1;
}
-static void
-display_text_draw(struct font_freetype_text *text,
- struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, int color, struct point *p) {
+static void display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, int color, struct point *p) {
int i, x, y, stride;
struct font_freetype_glyph *g, **gp;
unsigned char *shadow, *glyph;
@@ -730,10 +695,7 @@ display_text_draw(struct font_freetype_text *text,
stride = (g->w + 2) * 4;
if (color) {
shadow = g_malloc(stride * (g->h + 2));
- gr->freetype_methods.get_shadow(g, shadow,
- stride,
- &white,
- &transparent);
+ gr->freetype_methods.get_shadow(g, shadow, stride, &white, &transparent);
struct point p;
p.x=((x + g->x) >> 6)-1;
@@ -759,13 +721,7 @@ display_text_draw(struct font_freetype_text *text,
if (bg) {
glyph =
g_malloc(stride * g->h * 4);
- gr->freetype_methods.get_glyph(g,
- glyph,
- stride
- * 4,
- &black,
- &white,
- &transparent);
+ gr->freetype_methods.get_glyph(g, glyph, stride * 4, &black, &white, &transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
@@ -775,11 +731,7 @@ display_text_draw(struct font_freetype_text *text,
}
stride *= 4;
glyph = g_malloc(stride * g->h);
- gr->freetype_methods.get_glyph(g, glyph,
- stride,
- &black,
- &white,
- &transparent);
+ gr->freetype_methods.get_glyph(g, glyph, stride, &black, &white, &transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
@@ -793,10 +745,7 @@ display_text_draw(struct font_freetype_text *text,
}
}
-static void
-draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, struct graphics_font_priv *font,
- char *text, struct point *p, int dx, int dy) {
+static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
if ((gr->parent && !gr->parent->overlay_enabled)
|| (gr->parent && gr->parent->overlay_enabled
&& !gr->overlay_enabled)) {
@@ -812,9 +761,7 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
}
graphics_priv_root->dirty = 1;
- t = gr->freetype_methods.text_new(text,
- (struct font_freetype_font *)
- font, dx, dy);
+ t = gr->freetype_methods.text_new(text, (struct font_freetype_font *) font, dx, dy);
struct point p_eff;
p_eff.x = p->x;
@@ -825,30 +772,25 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
}
-static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct point *p, struct graphics_image_priv *img) {
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
draw_image_es(gr, p, img->img->w, img->img->h, img->img->pixels);
}
-static void
-draw_drag(struct graphics_priv *gr, struct point *p) {
+static void draw_drag(struct graphics_priv *gr, struct point *p) {
if (p) {
gr->p.x = p->x;
gr->p.y = p->y;
}
}
-static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
gr->background_gc = gc;
}
/*
* Draws map in background
*/
-static void
-draw_background(struct graphics_priv *gr) {
+static void draw_background(struct graphics_priv *gr) {
struct point p_eff;
GLf x[8];
@@ -882,8 +824,7 @@ draw_background(struct graphics_priv *gr) {
Map and overlays are rendered in an offscreen buffer (See render to texture)
and are recomposed altogether at draw_mode_end request for root
*/
-static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
GLfloat matrix[16];
struct graphics_priv *overlay = NULL;
int i;
@@ -932,19 +873,16 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
gr->mode = mode;
}
-static int
-graphics_opengl_fullscreen(struct window *w, int on) {
+static int graphics_opengl_fullscreen(struct window *w, int on) {
return 1;
}
-static void
-graphics_opengl_disable_suspend(struct window *w) {
+static void graphics_opengl_disable_suspend(struct window *w) {
// No op
}
-static GLuint
-load_shader(const char *shader_source, GLenum type) {
+static GLuint load_shader(const char *shader_source, GLenum type) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &shader_source, NULL);
@@ -953,16 +891,14 @@ load_shader(const char *shader_source, GLenum type) {
return shader;
}
-static void *
-get_data(struct graphics_priv *this, const char *type) {
+static void *get_data(struct graphics_priv *this, const char *type) {
GLuint vertexShader;
GLuint fragmentShader;
struct window* win;
int i;
if (!strcmp(type, "gtk_widget")) {
- fprintf(stderr,
- "Currently GTK gui is not yet supported with EGL graphics driver\n");
+ fprintf(stderr, "Currently GTK gui is not yet supported with EGL graphics driver\n");
return NULL;
}
@@ -972,8 +908,7 @@ get_data(struct graphics_priv *this, const char *type) {
glClearColor ( 0, 0, 0, 1);
glClear ( GL_COLOR_BUFFER_BIT );
- callback_list_call_attr_2(graphics_priv_root->cbl, attr_resize,
- GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
+ callback_list_call_attr_2(graphics_priv_root->cbl, attr_resize, GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
this->program = glCreateProgram();
vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
@@ -1007,17 +942,14 @@ get_data(struct graphics_priv *this, const char *type) {
}
-static void
-overlay_disable(struct graphics_priv *gr, int disable) {
+static void overlay_disable(struct graphics_priv *gr, int disable) {
gr->overlay_enabled = !disable;
gr->force_redraw = 1;
draw_mode(gr, draw_mode_end);
}
// Need more testing
-static void
-overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
- int wraparound) {
+static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) {
int changed = 0;
int w2, h2;
@@ -1061,9 +993,7 @@ overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gr->overlay_texture, 0);
}
- callback_list_call_attr_2(gr->cbl, attr_resize,
- GINT_TO_POINTER(gr->width),
- GINT_TO_POINTER(gr->height));
+ callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->width), GINT_TO_POINTER(gr->height));
}
}
@@ -1099,8 +1029,7 @@ static struct graphics_methods graphics_methods = {
NULL, /* hide_native_keyboard */
};
-static struct graphics_priv *
-graphics_opengl_new_helper(struct graphics_methods *meth) {
+static struct graphics_priv *graphics_opengl_new_helper(struct graphics_methods *meth) {
struct font_priv *(*font_freetype_new) (void *meth);
font_freetype_new = plugin_get_category_font("freetype");
@@ -1123,8 +1052,7 @@ graphics_opengl_new_helper(struct graphics_methods *meth) {
return this;
}
-static void
-create_framebuffer_texture(struct graphics_priv *gr) {
+static void create_framebuffer_texture(struct graphics_priv *gr) {
GLenum status;
// Prepare a new framebuffer object
glGenFramebuffers(1, &gr->framebuffer_name);
@@ -1145,9 +1073,7 @@ create_framebuffer_texture(struct graphics_priv *gr) {
}
}
-static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth,
- struct point *p, int w, int h, int wraparound) {
+static struct graphics_priv *overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
struct graphics_priv *this = graphics_opengl_new_helper(meth);
this->p.x = p->x;
@@ -1302,9 +1228,7 @@ static gboolean graphics_sdl_idle(void *data) {
}
-static struct graphics_priv *
-graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
- struct attr **attrs, struct callback_list *cbl) {
+static struct graphics_priv *graphics_opengl_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
struct attr *attr;
if (!event_request_system("glib", "graphics_opengl_new"))
return NULL;
@@ -1392,8 +1316,7 @@ error:
return NULL;
}
-void
-plugin_init(void) {
+void plugin_init(void) {
plugin_register_category_graphics("egl", graphics_opengl_new);
}