1 | /* |
2 | Copyright (c) 2013, Broadcom Europe Ltd |
3 | Copyright (c) 2013, Tim Gover |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: |
8 | * Redistributions of source code must retain the above copyright |
9 | notice, this list of conditions and the following disclaimer. |
10 | * Redistributions in binary form must reproduce the above copyright |
11 | notice, this list of conditions and the following disclaimer in the |
12 | documentation and/or other materials provided with the distribution. |
13 | * Neither the name of the copyright holder nor the |
14 | names of its contributors may be used to endorse or promote products |
15 | derived from this software without specific prior written permission. |
16 | |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
29 | #ifndef RASPITEX_UTIL_H_ |
30 | #define RASPITEX_UTIL_H_ |
31 | |
32 | #define VCOS_LOG_CATEGORY (&raspitex_log_category) |
33 | #include <math.h> |
34 | #include <stdio.h> |
35 | #include <stdlib.h> |
36 | #include <string.h> |
37 | #include <EGL/egl.h> |
38 | #include <EGL/eglext.h> |
39 | #include "RaspiTex.h" |
40 | #include "interface/vcos/vcos.h" |
41 | |
42 | extern VCOS_LOG_CAT_T raspitex_log_category; |
43 | |
44 | #define SHADER_MAX_ATTRIBUTES 16 |
45 | #define SHADER_MAX_UNIFORMS 16 |
46 | /** |
47 | * Container for a simple shader program. The uniform and attribute locations |
48 | * are automatically setup by raspitex_build_shader_program. |
49 | */ |
50 | typedef struct RASPITEXUTIL_SHADER_PROGRAM_T |
51 | { |
52 | const char *vertex_source; /// Pointer to vertex shader source |
53 | const char *fragment_source; /// Pointer to fragment shader source |
54 | |
55 | /// Array of uniform names for raspitex_build_shader_program to process |
56 | const char *uniform_names[SHADER_MAX_UNIFORMS]; |
57 | /// Array of attribute names for raspitex_build_shader_program to process |
58 | const char *attribute_names[SHADER_MAX_ATTRIBUTES]; |
59 | |
60 | GLint vs; /// Vertex shader handle |
61 | GLint fs; /// Fragment shader handle |
62 | GLint program; /// Shader program handle |
63 | |
64 | /// The locations for uniforms defined in uniform_names |
65 | GLint uniform_locations[SHADER_MAX_UNIFORMS]; |
66 | |
67 | /// The locations for attributes defined in attribute_names |
68 | GLint attribute_locations[SHADER_MAX_ATTRIBUTES]; |
69 | } RASPITEXUTIL_SHADER_PROGRAM_T; |
70 | |
71 | |
72 | /* Uncomment to enable extra GL error checking */ |
73 | //#define CHECK_GL_ERRORS |
74 | #if defined(CHECK_GL_ERRORS) |
75 | #define GLCHK(X) \ |
76 | do { \ |
77 | GLenum err = GL_NO_ERROR; \ |
78 | X; \ |
79 | while ((err = glGetError())) \ |
80 | { \ |
81 | vcos_log_error("GL error 0x%x in " #X "file %s line %d", err, __FILE__,__LINE__); \ |
82 | vcos_assert(err == GL_NO_ERROR); \ |
83 | exit(err); \ |
84 | } \ |
85 | } \ |
86 | while(0) |
87 | #else |
88 | #define GLCHK(X) X |
89 | #endif /* CHECK_GL_ERRORS */ |
90 | |
91 | /* Default GL scene ops functions */ |
92 | int raspitexutil_create_native_window(RASPITEX_STATE *raspitex_state); |
93 | int raspitexutil_gl_init_1_0(RASPITEX_STATE *raspitex_state); |
94 | int raspitexutil_gl_init_2_0(RASPITEX_STATE *raspitex_state); |
95 | int raspitexutil_update_model(RASPITEX_STATE* raspitex_state); |
96 | int raspitexutil_redraw(RASPITEX_STATE* raspitex_state); |
97 | void raspitexutil_gl_term(RASPITEX_STATE *raspitex_state); |
98 | void raspitexutil_destroy_native_window(RASPITEX_STATE *raspitex_state); |
99 | int raspitexutil_create_textures(RASPITEX_STATE *raspitex_state); |
100 | int raspitexutil_update_texture(RASPITEX_STATE *raspitex_state, |
101 | EGLClientBuffer mm_buf); |
102 | int raspitexutil_update_y_texture(RASPITEX_STATE *raspitex_state, |
103 | EGLClientBuffer mm_buf); |
104 | int raspitexutil_update_u_texture(RASPITEX_STATE *raspitex_state, |
105 | EGLClientBuffer mm_buf); |
106 | int raspitexutil_update_v_texture(RASPITEX_STATE *raspitex_state, |
107 | EGLClientBuffer mm_buf); |
108 | int raspitexutil_capture_bgra(struct RASPITEX_STATE *state, |
109 | uint8_t **buffer, size_t *buffer_size); |
110 | void raspitexutil_close(RASPITEX_STATE* raspitex_state); |
111 | |
112 | /* Utility functions */ |
113 | int raspitexutil_build_shader_program(RASPITEXUTIL_SHADER_PROGRAM_T *p); |
114 | void raspitexutil_brga_to_rgba(uint8_t *buffer, size_t size); |
115 | |
116 | #endif /* RASPITEX_UTIL_H_ */ |
117 | |