RAPICAM_3-15-2015
RaspiTexUtil.h
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 
51 {
52  const char *vertex_source;
53  const char *fragment_source;
54 
56  const char *uniform_names[SHADER_MAX_UNIFORMS];
58  const char *attribute_names[SHADER_MAX_ATTRIBUTES];
59 
60  GLint vs;
61  GLint fs;
62  GLint program;
63 
65  GLint uniform_locations[SHADER_MAX_UNIFORMS];
66 
68  GLint attribute_locations[SHADER_MAX_ATTRIBUTES];
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 */
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);
99 int raspitexutil_create_textures(RASPITEX_STATE *raspitex_state);
100 int raspitexutil_update_texture(RASPITEX_STATE *raspitex_state,
101  EGLClientBuffer mm_buf);
103  EGLClientBuffer mm_buf);
105  EGLClientBuffer mm_buf);
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 */
114 void raspitexutil_brga_to_rgba(uint8_t *buffer, size_t size);
115 
116 #endif /* RASPITEX_UTIL_H_ */
int raspitexutil_update_y_texture(RASPITEX_STATE *raspitex_state, EGLClientBuffer mm_buf)
Definition: RaspiTexUtil.c:367
void raspitexutil_gl_term(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:47
int raspitexutil_update_u_texture(RASPITEX_STATE *raspitex_state, EGLClientBuffer mm_buf)
Definition: RaspiTexUtil.c:381
int raspitexutil_capture_bgra(RASPITEX_STATE *state, uint8_t **buffer, size_t *buffer_size)
Definition: RaspiTexUtil.c:466
int raspitexutil_build_shader_program(RASPITEXUTIL_SHADER_PROGRAM_T *p)
Definition: RaspiTexUtil.c:502
const char * fragment_source
Pointer to vertex shader source.
Definition: RaspiTexUtil.h:53
int raspitexutil_redraw(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:419
void raspitexutil_close(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:429
GLint attribute_locations[SHADER_MAX_ATTRIBUTES]
The locations for attributes defined in attribute_names.
Definition: RaspiTexUtil.h:68
GLint uniform_locations[SHADER_MAX_UNIFORMS]
Shader program handle.
Definition: RaspiTexUtil.h:65
int raspitexutil_create_native_window(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:80
int raspitexutil_update_model(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:408
GLint program
Fragment shader handle.
Definition: RaspiTexUtil.h:62
void raspitexutil_destroy_native_window(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:141
const char * uniform_names[SHADER_MAX_UNIFORMS]
Pointer to fragment shader source.
Definition: RaspiTexUtil.h:56
int raspitexutil_update_v_texture(RASPITEX_STATE *raspitex_state, EGLClientBuffer mm_buf)
Definition: RaspiTexUtil.c:395
Definition: RaspiTexUtil.h:50
void raspitexutil_brga_to_rgba(uint8_t *buffer, size_t size)
Definition: RaspiTexUtil.c:439
Definition: RaspiTex.h:123
int raspitexutil_update_texture(RASPITEX_STATE *raspitex_state, EGLClientBuffer mm_buf)
Definition: RaspiTexUtil.c:353
GLint fs
Vertex shader handle.
Definition: RaspiTexUtil.h:61
int raspitexutil_gl_init_2_0(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:283
int raspitexutil_gl_init_1_0(RASPITEX_STATE *raspitex_state)
Definition: RaspiTexUtil.c:242
const char * attribute_names[SHADER_MAX_ATTRIBUTES]
Array of attribute names for raspitex_build_shader_program to process.
Definition: RaspiTexUtil.h:58