render: gl: Export gl-point-size.
[chickadee.git] / chickadee / render / gl.scm
1 ;;; Chickadee Game Toolkit
2 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
3 ;;;
4 ;;; Chickadee is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published
6 ;;; by the Free Software Foundation, either version 3 of the License,
7 ;;; or (at your option) any later version.
8 ;;;
9 ;;; Chickadee is distributed in the hope that it will be useful, but
10 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see
16 ;;; <http://www.gnu.org/licenses/>.
17
18 ;;; Commentary:
19 ;;
20 ;; Custom wrappers over low level OpenGL commands that aren't part of
21 ;; guile-opengl.
22 ;;
23 ;;; Code:
24
25 (define-module (chickadee render gl)
26 #:use-module (srfi srfi-4)
27 #:use-module ((system foreign) #:select (bytevector->pointer))
28 #:use-module (gl)
29 #:use-module ((gl low-level) #:renamer (symbol-prefix-proc '%))
30 #:use-module (gl enums)
31 #:use-module (gl runtime)
32 #:use-module (gl types))
33
34 (re-export (%glClearColor . gl-clear-color)
35 (%glScissor . gl-scissor)
36 (%glBlendFunc . gl-blend-func)
37 (%glBlendEquation . gl-blend-equation))
38
39 ;;;
40 ;;; 3.8.1 Texture Image Specification
41 ;;;
42
43 (re-export (%glTexImage3D . gl-texture-image-3d)
44 (%glTexImage2D . gl-texture-image-2d)
45 (%glTexImage1D . gl-texture-image-1d))
46
47 ;;;
48 ;;; 3.8.2 Alternate Texture Image Specification Commands
49 ;;;
50
51 (re-export (%glCopyTexImage2D . gl-copy-texture-image-2d)
52 (%glCopyTexImage1D . gl-copy-texture-image-1d)
53 (%glCopyTexSubImage3D . gl-copy-texture-sub-image-3d)
54 (%glCopyTexSubImage2D . gl-copy-texture-sub-image-2d)
55 (%glCopyTexSubImage1D . gl-copy-texture-sub-image-1d)
56 (%glTexSubImage3D . gl-texture-sub-image-3d)
57 (%glTexSubImage2D . gl-texture-sub-image-2d)
58 (%glTexSubImage1D . gl-texture-sub-image-1d))
59
60 ;;;
61 ;;; 3.8.3 Compressed Texture Images
62 ;;;
63
64 (re-export (%glCompressedTexImage1D . gl-compressed-texture-image-1d)
65 (%glCompressedTexImage2D . gl-compressed-texture-image-2d)
66 (%glCompressedTexImage3D . gl-compressed-texture-image-3d)
67 (%glCompressedTexSubImage1D . gl-compressed-texture-sub-image-1d)
68 (%glCompressedTexSubImage2D . gl-compressed-texture-sub-image-2d)
69 (%glCompressedTexSubImage3D . gl-compressed-texture-sub-image-3d))
70
71 ;;;
72 ;;; 3.8.4 Texture Parameters
73 ;;;
74
75 (re-export (%glTexParameteri . gl-texture-parameter)
76 (%glBindTexture . gl-bind-texture))
77
78 ;;;
79 ;;; Instancing extension
80 ;;;
81
82 (define-gl-procedure (glDrawArraysInstanced (mode GLenum)
83 (first GLint)
84 (count GLsizei)
85 (primcount GLsizei)
86 -> GLboolean)
87 "Draw multiple instances of a set of arrays.")
88
89 (define-gl-procedure (glVertexAttribDivisor (index GLuint)
90 (divisor GLuint)
91 -> void)
92 "Modify the rate at which generic vertex attributes advance during
93 instanced rendering.")
94
95 (export glDrawArraysInstanced
96 glVertexAttribDivisor)
97
98 ;;;
99 ;;; VBOs
100 ;;;
101
102 (re-export (%glGenBuffers . gl-gen-buffers)
103 (%glDeleteBuffers . gl-delete-buffers)
104 (%glBufferData . gl-buffer-data)
105 (%glBufferSubData . gl-buffer-sub-data)
106 (%glMapBuffer . gl-map-buffer)
107 (%glUnmapBuffer . gl-unmap-buffer))
108
109 ;;;
110 ;;; VAOs
111 ;;;
112
113 (define-gl-procedure (glGenVertexArrays (n GLsizei)
114 (arrays GLuint-*)
115 -> void)
116 "Generate N vertex arrays.")
117
118 (define-gl-procedure (glDeleteVertexArrays (n GLsizei)
119 (arrays GLuint-*)
120 -> void)
121 "Delete vertex array objects.")
122
123 (define-gl-procedure (glBindVertexArray (array GLuint)
124 -> void)
125 "Bind vertex array object ARRAY.")
126
127 (define-gl-procedure (glEnableVertexAttribArray (index GLuint)
128 -> void)
129 "Enable or disable a generic vertex attribute array.")
130
131 (define-gl-procedure (glVertexAttribPointer (index GLuint)
132 (size GLint)
133 (type GLenum)
134 (normalized GLboolean)
135 (stride GLsizei)
136 (pointer GLvoid-*)
137 -> void)
138 "Define an array of generic vertex attribute data.")
139
140 (define-gl-procedure (glDrawElements (mode GLenum)
141 (count GLsizei)
142 (type GLenum)
143 (indices GLvoid-*)
144 -> void)
145 "Render primitives from array data.")
146
147 (export (glGenVertexArrays . gl-gen-vertex-arrays)
148 (glDeleteVertexArrays . gl-delete-vertex-arrays)
149 (glBindVertexArray . gl-bind-vertex-array)
150 (glEnableVertexAttribArray . gl-enable-vertex-attrib-array)
151 (glVertexAttribPointer . gl-vertex-attrib-pointer)
152 (glDrawElements . gl-draw-elements))
153
154 (define-syntax-rule (with-gl-client-state state body ...)
155 (begin
156 (gl-enable-client-state state)
157 body ...
158 (gl-disable-client-state state)))
159
160 (export with-gl-client-state)
161
162 ;;;
163 ;;; Framebuffers
164 ;;;
165
166 (define-gl-procedure (glGenFramebuffers (n GLsizei)
167 (ids GLuint-*)
168 -> void)
169 "Generate framebuffer object names.")
170
171 (define-gl-procedure (glDeleteFramebuffers (n GLsizei)
172 (framebuffers GLuint-*)
173 -> void)
174 "Delete framebuffer objects.")
175
176 (define-gl-procedure (glBindFramebuffer (target GLenum)
177 (framebuffer GLuint)
178 -> void)
179 "Bind a framebuffer to a framebuffer target.")
180
181 (define-gl-procedure (glFramebufferTexture2D (target GLenum)
182 (attachment GLenum)
183 (textarget GLenum)
184 (texture GLuint)
185 (level GLint)
186 -> void)
187 "Attach a level of a texture object as a logical buffer to the
188 currently bound framebuffer object.")
189
190 (define-gl-procedure (glCheckFramebufferStatus (target GLenum)
191 -> GLenum)
192 "Return the framebuffer completeness status of a framebuffer
193 object.")
194
195 (define-gl-procedure (glGenRenderbuffers (n GLsizei)
196 (ids GLuint-*)
197 -> void)
198 "Generate renderbuffer object names.")
199
200 (define-gl-procedure (glDeleteRenderbuffers (n GLsizei)
201 (renderbuffers GLuint-*)
202 -> void)
203 "Delete renderbuffer objects.")
204
205 (define-gl-procedure (glBindRenderbuffer (target GLenum)
206 (renderbuffer GLuint)
207 -> void)
208 "Bind a named renderbuffer object.")
209
210 (define-gl-procedure (glRenderbufferStorage (target GLenum)
211 (internalformat GLenum)
212 (width GLsizei)
213 (height GLsizei)
214 -> void)
215 "Create and initialize a renderbuffer object's data store.")
216
217 (define-gl-procedure (glFramebufferRenderbuffer (target GLenum)
218 (attachment GLenum)
219 (renderbuffertarget GLenum)
220 (renderbuffer GLuint)
221 -> void)
222 "Attach a renderbuffer object to a framebuffer object.")
223
224 (export (glGenFramebuffers . gl-gen-framebuffers)
225 (glDeleteFramebuffers . gl-delete-framebuffers)
226 (glBindFramebuffer . gl-bind-framebuffer)
227 (glFramebufferTexture2D . gl-framebuffer-texture-2d)
228 (glCheckFramebufferStatus . gl-check-framebuffer-status)
229 (glGenRenderbuffers . gl-gen-renderbuffers)
230 (glDeleteRenderbuffers . gl-delete-renderbuffers)
231 (glBindRenderbuffer . gl-bind-renderbuffer)
232 (glRenderbufferStorage . gl-renderbuffer-storage)
233 (glFramebufferRenderbuffer . gl-framebuffer-renderbuffer))
234
235 (re-export (%glDrawBuffers . gl-draw-buffers))
236
237 \f
238 ;;;
239 ;;; Shaders
240 ;;;
241
242 (define-gl-procedure (glUniform1ui (location GLint)
243 (v0 GLuint)
244 -> void)
245 "Specify the value of a uniform variable for the current program object")
246
247 (export (glUniform1ui . gl-uniform1ui))
248
249 (re-export (%glUseProgram . gl-use-program)
250 (%glDeleteProgram . gl-delete-program)
251 (%glDetachShader . gl-detach-shader)
252 (%glLinkProgram . gl-link-program)
253 (%glBindAttribLocation . gl-bind-attrib-location)
254 (%glAttachShader . gl-attach-shader)
255 (%glGetAttribLocation . gl-get-attrib-location)
256 (%glGetUniformLocation . gl-get-uniform-location)
257 (%glCreateProgram . gl-create-program)
258 (%glGetProgramInfoLog . gl-get-program-info-log)
259 (%glGetProgramiv . gl-get-programiv)
260 (%glDeleteProgram . gl-delete-program)
261 (%glDeleteShader . gl-delete-shader)
262 (%glGetShaderiv . gl-get-shaderiv)
263 (%glGetShaderInfoLog . gl-get-shader-info-log)
264 (%glCompileShader . gl-compile-shader)
265 (%glShaderSource . gl-shader-source)
266 (%glCreateShader . gl-create-shader)
267 (%glGetActiveUniform . gl-get-active-uniform)
268 (%glGetActiveAttrib . gl-get-active-attrib)
269 (%glUniform1i . gl-uniform1i)
270 (%glUniform2i . gl-uniform2i)
271 (%glUniform3i . gl-uniform3i)
272 (%glUniform4i . gl-uniform4i)
273 (%glUniform1f . gl-uniform1f)
274 (%glUniform2f . gl-uniform2f)
275 (%glUniform2fv . gl-uniform2fv)
276 (%glUniform3f . gl-uniform3f)
277 (%glUniform4f . gl-uniform4f)
278 (%glUniformMatrix4fv . gl-uniform-matrix4fv)
279 (%glUniform4f . gl-uniform4f))
280
281 (re-export (%glPointSize . gl-point-size))