wlt: fix shl_hook API changes
[platform/upstream/kmscon.git] / src / static_gl.h
1 /*
2  * kmscon - OpenGL Helpers
3  *
4  * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
5  * Copyright (c) 2011 University of Tuebingen
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files
9  * (the "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27 /*
28  * OpenGL Helpers
29  * This file provides several helper functions that are commonly used when
30  * working with OpenGL.
31  */
32
33 #ifndef GL_H_INCLUDED
34 #define GL_H_INCLUDED
35
36 #include <GLES2/gl2.h>
37 #include <GLES2/gl2ext.h>
38 #include <stdbool.h>
39 #include <stdlib.h>
40 #include <stddef.h>
41 #include "shl_llog.h"
42
43 /*
44  * Math Helpers
45  * The gl_m4 type is a 4x4 matrix of floats. The gl_m4_stack is a stack of m4
46  * matrices where you can only access the top-most member.
47  */
48
49 struct gl_m4_stack;
50
51 void gl_m4_identity(float *m);
52 void gl_m4_copy(float *dest, const float *src);
53 void gl_m4_mult_dest(float *dest, const float *n, const float *m);
54 void gl_m4_mult(float *n, const float *m);
55 void gl_m4_translate(float *m, float x, float y, float z);
56 void gl_m4_scale(float *m, float x, float y, float z);
57 void gl_m4_transpose_dest(float *dest, const float *src);
58 void gl_m4_transpose(float *m);
59
60 int gl_m4_stack_new(struct gl_m4_stack **out);
61 void gl_m4_stack_free(struct gl_m4_stack *stack);
62 float *gl_m4_stack_push(struct gl_m4_stack *stack);
63 float *gl_m4_stack_pop(struct gl_m4_stack *stack);
64 float *gl_m4_stack_tip(struct gl_m4_stack *stack);
65
66 /*
67  * Shader Helpers
68  * These helpers load, compile and link shaders and allow easy attribute/uniform
69  * access.
70  */
71
72 struct gl_shader;
73
74 int gl_shader_new(struct gl_shader **out, const char *vert, const char *frag,
75                   char **attr, size_t attr_count, llog_submit_t llog);
76 void gl_shader_ref(struct gl_shader *shader);
77 void gl_shader_unref(struct gl_shader *shader);
78 GLuint gl_shader_get_uniform(struct gl_shader *shader, const char *name);
79 void gl_shader_use(struct gl_shader *shader);
80
81 void gl_tex_new(GLuint *tex, size_t num);
82 void gl_tex_free(GLuint *tex, size_t num);
83 void gl_tex_load(GLuint tex, unsigned int width, unsigned int stride,
84                  unsigned int height, uint8_t *buf);
85
86 void gl_clear_error();
87 bool gl_has_error(struct gl_shader *shader);
88 const char *gl_err_to_str(GLenum err);
89
90 #endif /* GL_H_INCLUDED */