summaryrefslogtreecommitdiffstats
path: root/hacks/glx/glsl-utils.h
blob: 20edc9dba7dd0980e55053e8b636bb48bc3fc4ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* glsl-utils.h --- support functions for GLSL in OpenGL hacks.
 * Copyright (c) 2020-2021 Carsten Steger <carsten@mirsanmir.org>
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.  No representations are made about the suitability of this
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.
 */


#ifndef __GLSL_UTILS_H__
#define __GLSL_UTILS_H__

#ifdef HAVE_GLSL


/* Column-major linearized matrix coordinate */
#define GLSL__LINCOOR(r,c,h) ((c)*(h)+(r))


/* Copy a 4x4 column-major matrix: c = m. */
extern void glsl_CopyMatrix(GLfloat c[16], GLfloat m[16]);

/* Create a 4x4 column-major identity matrix. */
extern void glsl_Identity(GLfloat c[16]);

/* Multiply two 4x4 column-major matrices: c = c*m. */
extern void glsl_MultMatrix(GLfloat c[16], GLfloat m[16]);

/* Multiply a 4x4 column-major matrix by a rotation matrix that rotates
   around the axis (x,y,z) by the angle angle: c = c*r(angle,x,y,z). */
extern void glsl_Rotate(GLfloat c[16], GLfloat angle, GLfloat x, GLfloat y,
                        GLfloat z);

/* Multiply a 4x4 column-major matrix by a matrix that stretches, shrinks,
   or reflects an object along the axes: c = c*s(sx,sy,sz). */
extern void glsl_Scale(GLfloat c[16], GLfloat sx, GLfloat sy, GLfloat sz);

/* Multiply a 4x4 column-major matrix by a matrix that translates an object
   by a translation vector: c = c*t(tx,ty,tz). */
extern void glsl_Translate(GLfloat c[16], GLfloat tx, GLfloat ty, GLfloat tz);

/* Add a perspective projection to a 4x4 column-major matrix. */
extern void glsl_Perspective(GLfloat c[16], GLfloat fovy, GLfloat aspect,
                             GLfloat z_near, GLfloat z_far);

/* Add an orthographic projection to a 4x4 column-major matrix. */
extern void glsl_Orthographic(GLfloat c[16], GLfloat left, GLfloat right,
                              GLfloat bottom, GLfloat top,
                              GLfloat nearval, GLfloat farval);

/* Get the OpenGL and GLSL versions. */
extern GLboolean glsl_GetGlAndGlslVersions(GLint *gl_major,
                                           GLint *gl_minor,
                                           GLint *glsl_major,
                                           GLint *glsl_minor,
                                           GLboolean *gl_gles3);

/* Compile and link a vertex and a Fragment shader into a GLSL program. */
extern GLboolean glsl_CompileAndLinkShaders(GLsizei vertex_shader_count,
                                        const GLchar **vertex_shader_source,
                                        GLsizei fragment_shader_count,
                                        const GLchar **fragment_shader_source,
                                        GLuint *shader_program);


#endif /* HAVE_GLSL */


#endif /* __GLSL_UTILS_H__ */