naev 0.12.5
opengl.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7/* Include header generated by glad */
8#include "SDL_video.h"
9#include "glad.h"
11
12/* We put all the other opengl stuff here to only have to include one header. */
13#include "mat4.h"
14#include "opengl_render.h" // IWYU pragma: export
15#include "opengl_shader.h" // IWYU pragma: export
16#include "opengl_tex.h" // IWYU pragma: export
17#include "opengl_vbo.h" // IWYU pragma: export
18
19#define OPENGL_NUM_FBOS 4
24
25/*
26 * Contains info about the opengl screen
27 */
28#define OPENGL_DOUBLEBUF ( 1 << 1 )
29#define OPENGL_VSYNC ( 1 << 2 )
30#define OPENGL_SUBROUTINES \
31 ( 1 << 3 )
33#define gl_has( f ) ( gl_screen.flags & ( f ) )
37typedef struct glInfo_ {
38 int major;
39 int minor;
40 int glsl;
41 int x;
42 int y;
43 /* Viewport considers x/y offset. */
44 int w;
45 int h;
46 /* Scaled window is the effective window resolution without considering
47 * offsets. */
48 int nw;
49 int nh;
50 /* Real window resolution is the real window resolution, unscaled and without
51 * offsets. */
52 int rw;
53 int rh;
54 double scale;
55 double wscale;
56 double hscale;
57 double dwscale;
58 double dhscale;
59 double mxscale;
60 double myscale;
61 int depth;
62 int r;
63 int g;
64 int b;
65 int a;
66 unsigned int flags;
67 int tex_max;
69 int fsaa;
70 SDL_Window *window;
71 SDL_GLContext context;
72 GLuint current_fbo;
73 GLuint fbo[OPENGL_NUM_FBOS];
74 GLuint fbo_tex[OPENGL_NUM_FBOS];
75 GLuint
76 fbo_depth_tex[OPENGL_NUM_FBOS];
77} glInfo;
78extern glInfo gl_screen; /* local structure set with gl_init and co */
79
80extern mat4 gl_view_matrix;
81
82#define SCREEN_X gl_screen.x
83#define SCREEN_Y gl_screen.y
84#define SCREEN_W gl_screen.w
85#define SCREEN_H gl_screen.h
86
87/*
88 * initialization / cleanup
89 */
90int gl_init( unsigned int extra_flags );
91void gl_exit( void );
92void gl_resize( void );
93
94/*
95 * Extensions and version.
96 */
97GLboolean gl_hasVersion( int major, int minor );
98
99/*
100 * Viewport.
101 */
102void gl_windowToScreenPos( int *sx, int *sy, int wx, int wy );
103void gl_screenToWindowPos( int *wx, int *wy, int sx, int sy );
104void gl_viewport( int x, int y, int w, int h );
105void gl_defViewport( void );
106void gl_setDefViewport( int x, int y, int w, int h );
107int gl_setupFullscreen( void );
108
109/*
110 * misc
111 */
112void gl_colourblind( void );
113GLenum gl_stringToFilter( const char *s );
114GLenum gl_stringToClamp( const char *s );
115GLenum gl_stringToBlendFunc( const char *s );
116GLenum gl_stringToBlendFactor( const char *s );
117void gl_screenshot( const char *filename );
118void gl_saveFboDepth( GLuint fbo, const char *filename );
119#ifdef DEBUGGING
120#define gl_checkErr() gl_checkHandleError( __func__, __LINE__ )
121int gl_checkHandleError( const char *func, int line );
122#else /* DEBUGGING */
123#define gl_checkErr() 0
124#endif /* DEBUGGING */
void gl_setDefViewport(int x, int y, int w, int h)
Sets the default viewport.
Definition opengl.c:743
void gl_screenshot(const char *filename)
Takes a screenshot.
Definition opengl.c:106
void gl_defViewport(void)
Resets viewport to default.
Definition opengl.c:754
void gl_colourblind(void)
Enables or disables the colourblind shader.
Definition opengl.c:878
GLenum gl_stringToBlendFactor(const char *s)
Gets a blend factor from a string.
Definition opengl.c:847
void gl_resize(void)
Handles a window resize and resets gl_screen parameters.
Definition opengl.c:689
void gl_screenToWindowPos(int *wx, int *wy, int sx, int sy)
Translates the screen position to windos position.
Definition opengl.c:775
void gl_exit(void)
Cleans up OpenGL, the works.
Definition opengl.c:931
void gl_viewport(int x, int y, int w, int h)
Sets the opengl viewport.
Definition opengl.c:715
int gl_init(unsigned int extra_flags)
Initializes SDL/OpenGL and the works.
Definition opengl.c:600
void gl_windowToScreenPos(int *sx, int *sy, int wx, int wy)
Translates the window position to screen position.
Definition opengl.c:762
GLenum gl_stringToBlendFunc(const char *s)
Gets a blend function from a string.
Definition opengl.c:825
GLenum gl_stringToFilter(const char *s)
Gets the associated min/mag filter from a string.
Definition opengl.c:791
GLboolean gl_hasVersion(int major, int minor)
Checks to see if opengl version is at least major.minor.
Definition opengl.c:205
glInfo gl_screen
Definition opengl.c:47
GLenum gl_stringToClamp(const char *s)
Gets the associated min/mag filter from a string.
Definition opengl.c:807
int gl_setupFullscreen(void)
Tries to apply the configured display mode to the window.
Definition opengl.c:340
Stores data about the current opengl environment.
Definition opengl.h:37
double dwscale
Definition opengl.h:57
int depth
Definition opengl.h:61
double scale
Definition opengl.h:54
int major
Definition opengl.h:38
int y
Definition opengl.h:42
int b
Definition opengl.h:64
int g
Definition opengl.h:63
int minor
Definition opengl.h:39
double wscale
Definition opengl.h:55
int x
Definition opengl.h:41
double myscale
Definition opengl.h:60
int w
Definition opengl.h:44
double dhscale
Definition opengl.h:58
int rh
Definition opengl.h:53
int fsaa
Definition opengl.h:69
int r
Definition opengl.h:62
int glsl
Definition opengl.h:40
GLuint fbo_tex[OPENGL_NUM_FBOS]
Definition opengl.h:74
double mxscale
Definition opengl.h:59
SDL_Window * window
Definition opengl.h:70
int a
Definition opengl.h:65
double hscale
Definition opengl.h:56
GLuint fbo[OPENGL_NUM_FBOS]
Definition opengl.h:73
int tex_max
Definition opengl.h:67
SDL_GLContext context
Definition opengl.h:71
int rw
Definition opengl.h:52
int h
Definition opengl.h:45
unsigned int flags
Definition opengl.h:66
int nw
Definition opengl.h:48
GLuint fbo_depth_tex[OPENGL_NUM_FBOS]
Definition opengl.h:76
int multitex_max
Definition opengl.h:68
int nh
Definition opengl.h:49
GLuint current_fbo
Definition opengl.h:72
Definition mat4.h:12