FB Graphics
FBGraphics (FBG) : Simple C 16, 24, 32 bpp generic graphics library with parallelism support and custom backend.
fbg_opengl_es2.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2019, 2020 Julien Verneuil
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the organization nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL Julien Verneuil BE LIABLE FOR ANY
20  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef FB_GRAPHICS_OPENGL_ES2_H
29 #define FB_GRAPHICS_OPENGL_ES2_H
30 
31  #include <sys/ioctl.h>
32  #include <linux/fb.h>
33  #include <unistd.h>
34  #include <fcntl.h>
35 
36  #include <GLES2/gl2.h>
37  #include <EGL/egl.h>
38  #include <EGL/eglext.h>
39 
40 #ifdef FBG_RPI
41  #include "bcm_host.h"
42 #endif
43 
44  #include "fbgraphics.h"
45 
48 #ifndef FBG_RPI
49  int fd;
52  struct fb_var_screeninfo vinfo;
53 #endif
54  EGLDisplay egl_display;
57  EGLContext egl_context;
59  EGLContext egl_surface;
61  void *egl_image;
65  GLuint fbg_vbo;
67  GLuint fbg_texture;
70  };
71 
73  struct _fbg_vbo_data {
74  // VBO (vertices)
75  GLuint vbo;
76  // VBO (texcoords)
77  GLuint tbo;
78  // VBO (indices)
79  GLuint ibo;
80  // VBO (normals)
81  GLuint nbo;
82  // VBO (colors)
83  GLuint cbo;
84  };
85 
87  extern const GLfloat fbg_gles2Quad[];
88 
90  extern const char *fbg_gles2SimpleVs;
91 
93  extern const char *fbg_gles2SimpleFs;
94 
96 
101 #ifdef FBG_RPI
102  extern struct _fbg *fbg_gles2Setup(int components);
103 #else
104  extern struct _fbg *fbg_gles2Setup(const char *fb_device, int components);
105 #endif
106 
108  extern void fbg_gles2Clear();
109 
111 
114  extern void fbg_gles2UpdateBuffer(struct _fbg *fbg);
115 
117 
121  extern int fbg_gles2ShouldClose(struct _fbg *fbg);
122 
124 
129  GLuint fbg_gles2CreateTextureFromImage(struct _fbg *fbg, struct _fbg_img *img);
130 
131  //-- A SET OF RAW OPENGL UTILITY FUNCTIONS --
133 
139  extern GLuint fbg_gles2CreateTexture(GLuint width, GLuint height, GLint internal_format);
140 
142 
156  extern struct _fbg_vbo_data * fbg_gles2CreateVBO(GLsizeiptr indices_count, const GLvoid *indices_data, size_t sizeof_indice_type,
157  GLsizeiptr vertices_count, const GLvoid *vertices_data,
158  GLsizeiptr texcoords_count, const GLvoid *texcoords_data,
159  GLsizeiptr normals_count, const GLvoid *normals_data,
160  GLsizeiptr colors_count, const GLvoid *colors_data);
161 
163 
166  extern void fbg_gles2FreeVBOData(struct _fbg_vbo_data *vbo_data);
167 
169 
174  extern GLuint fbg_gles2CreateVBOvu(GLsizeiptr data_count, const GLvoid *data);
175 
177 
181  //extern GLuint fbg_gles2CreateFBO(GLuint texture);
182 
184 
189  extern GLuint fbg_gles2CreateShader(GLenum type, const GLchar *source);
190 
192 
197  extern GLuint fbg_gles2CreateShaderFromFile(GLenum type, const char *filename);
198 
200 
205  extern GLuint fbg_gles2CreateProgram(GLuint vertex_shader, GLuint fragment_shader);
206 
208 
213  extern GLenum fbg_gles2CreateProgramFromFiles(const char *vs, const char *fs);
214 
216 
221  extern GLenum fbg_gles2CreateProgramFromString(const char *vs, const char *fs);
222 
223 #endif
struct which hold usual VBO data for 3D objects
int components
Display components amount (3 = 24 BPP / 4 = 32 BPP)
Definition: fbgraphics.h:176
EGLContext egl_surface
EGL surface.
EGLDisplay egl_display
EGL display.
void * egl_image
EGL image.
GLuint fbg_texture
FBG texture (updated at each frames)
int fd
Framebuffer file descriptor.
struct _fbg * fbg_gles2Setup(const char *fb_device, int components)
initialize a FB Graphics OpenGL ES 2 (fbdev or RPI direct) context
GLuint fbg_gles2CreateTexture(GLuint width, GLuint height, GLint internal_format)
create an empty non-interpolated (NEAREST) GL texture
GLuint fbg_gles2CreateTextureFromImage(struct _fbg *fbg, struct _fbg_img *img)
create a non-interpolated (NEAREST) GL texture from a FBG image
int update_buffer
tell wether fbg_gles2 should update fbg disp_buffer after rendering
const char * fbg_gles2SimpleVs
Simple vertex shader (screen quad, vertices + UV)
int width
Display width in pixels.
Definition: fbgraphics.h:170
GLuint fbg_gles2CreateVBOvu(GLsizeiptr data_count, const GLvoid *data)
create a VBO from vertices + UV data packed into a single array
int fbg_gles2ShouldClose(struct _fbg *fbg)
Query the user requested (window close etc) close status.
int height
Display height in pixels.
Definition: fbgraphics.h:172
const GLfloat fbg_gles2Quad[]
Simple quad geometry (vertices + UV)
void fbg_gles2UpdateBuffer(struct _fbg *fbg)
this update FBG disp_buffer with the actual rendered OpenGL content
GLuint fbg_gles2CreateShader(GLenum type, const GLchar *source)
create a FBO
GLuint fbg_vbo
FBG VBO.
struct _fbg_vbo_data * fbg_gles2CreateVBO(GLsizeiptr indices_count, const GLvoid *indices_data, size_t sizeof_indice_type, GLsizeiptr vertices_count, const GLvoid *vertices_data, GLsizeiptr texcoords_count, const GLvoid *texcoords_data, GLsizeiptr normals_count, const GLvoid *normals_data, GLsizeiptr colors_count, const GLvoid *colors_data)
create a VBO from indexed data, support for vertices, UVs, normals and colors
GLenum simple_program
Simple GLSL program (screen-aligned textured quad)
const char * fbg_gles2SimpleFs
Simple textured fragment shader.
void fbg_gles2FreeVBOData(struct _fbg_vbo_data *vbo_data)
free VBO data (created with fbg_gles2CreateVBO)
GLuint fbg_gles2CreateShaderFromFile(GLenum type, const char *filename)
create a shader from the content of a file
FB Graphics context data structure.
Definition: fbgraphics.h:123
void fbg_gles2Clear()
OpenGL clear.
OpenGL ES 2.0 wrapper data structure.
struct fb_var_screeninfo vinfo
Framebuffer device var. informations.
GLuint fbg_gles2CreateProgram(GLuint vertex_shader, GLuint fragment_shader)
create a vertex and/or fragment program
GLenum fbg_gles2CreateProgramFromFiles(const char *vs, const char *fs)
create a vertex and/or fragment/geometry program from a file
Image data structure.
Definition: fbgraphics.h:91
EGLContext egl_context
EGL context.
GLenum fbg_gles2CreateProgramFromString(const char *vs, const char *fs)
create a vertex and/or fragment/geometry program from a string