| 1 | module gl_bindings |
| 2 | use, intrinsic :: iso_c_binding |
| 3 | use types |
| 4 | implicit none |
| 5 | public |
| 6 | |
| 7 | ! OpenGL constants |
| 8 | integer(c_int), parameter :: GL_COLOR_BUFFER_BIT = int(Z'00004000', c_int) |
| 9 | integer(c_int), parameter :: GL_DEPTH_BUFFER_BIT = int(Z'00000100', c_int) |
| 10 | |
| 11 | ! Texture constants |
| 12 | integer(c_int), parameter :: GL_TEXTURE_2D = int(Z'0DE1', c_int) |
| 13 | integer(c_int), parameter :: GL_TEXTURE0 = int(Z'84C0', c_int) |
| 14 | integer(c_int), parameter :: GL_TEXTURE_MIN_FILTER = int(Z'2801', c_int) |
| 15 | integer(c_int), parameter :: GL_TEXTURE_MAG_FILTER = int(Z'2800', c_int) |
| 16 | integer(c_int), parameter :: GL_TEXTURE_WRAP_S = int(Z'2802', c_int) |
| 17 | integer(c_int), parameter :: GL_TEXTURE_WRAP_T = int(Z'2803', c_int) |
| 18 | integer(c_int), parameter :: GL_LINEAR = int(Z'2601', c_int) |
| 19 | integer(c_int), parameter :: GL_NEAREST = int(Z'2600', c_int) |
| 20 | integer(c_int), parameter :: GL_CLAMP_TO_EDGE = int(Z'812F', c_int) |
| 21 | integer(c_int), parameter :: GL_RED = int(Z'1903', c_int) |
| 22 | integer(c_int), parameter :: GL_UNSIGNED_BYTE = int(Z'1401', c_int) |
| 23 | integer(c_int), parameter :: GL_UNPACK_ALIGNMENT = int(Z'0CF5', c_int) |
| 24 | |
| 25 | ! Shader constants |
| 26 | integer(c_int), parameter :: GL_VERTEX_SHADER = int(Z'8B31', c_int) |
| 27 | integer(c_int), parameter :: GL_FRAGMENT_SHADER = int(Z'8B30', c_int) |
| 28 | |
| 29 | ! Buffer constants |
| 30 | integer(c_int), parameter :: GL_ARRAY_BUFFER = int(Z'8892', c_int) |
| 31 | integer(c_int), parameter :: GL_STATIC_DRAW = int(Z'88E4', c_int) |
| 32 | integer(c_int), parameter :: GL_DYNAMIC_DRAW = int(Z'88E8', c_int) |
| 33 | integer(c_int), parameter :: GL_STREAM_DRAW = int(Z'88E0', c_int) |
| 34 | |
| 35 | ! Drawing constants |
| 36 | integer(c_int), parameter :: GL_TRIANGLES = int(Z'0004', c_int) |
| 37 | integer(c_int), parameter :: GL_FLOAT = int(Z'1406', c_int) |
| 38 | integer(c_int), parameter :: GL_FALSE = 0 |
| 39 | integer(c_int), parameter :: GL_TRUE = 1 |
| 40 | |
| 41 | ! Blending constants |
| 42 | integer(c_int), parameter :: GL_BLEND = int(Z'0BE2', c_int) |
| 43 | integer(c_int), parameter :: GL_SRC_ALPHA = int(Z'0302', c_int) |
| 44 | integer(c_int), parameter :: GL_ONE_MINUS_SRC_ALPHA = int(Z'0303', c_int) |
| 45 | |
| 46 | ! Interface to C wrapper functions (in gl_loader.c) |
| 47 | interface |
| 48 | ! ============ Basic functions ============ |
| 49 | subroutine glViewport(x, y, width, height) bind(C, name="fortty_glViewport") |
| 50 | import :: c_int |
| 51 | integer(c_int), value :: x, y, width, height |
| 52 | end subroutine glViewport |
| 53 | |
| 54 | subroutine glClear(mask) bind(C, name="fortty_glClear") |
| 55 | import :: c_int |
| 56 | integer(c_int), value :: mask |
| 57 | end subroutine glClear |
| 58 | |
| 59 | subroutine glClearColor(red, green, blue, alpha) bind(C, name="fortty_glClearColor") |
| 60 | import :: c_float |
| 61 | real(c_float), value :: red, green, blue, alpha |
| 62 | end subroutine glClearColor |
| 63 | |
| 64 | ! ============ Texture functions ============ |
| 65 | subroutine glGenTextures(n, textures) bind(C, name="fortty_glGenTextures") |
| 66 | import :: c_int |
| 67 | integer(c_int), value :: n |
| 68 | integer(c_int), intent(out) :: textures(*) |
| 69 | end subroutine glGenTextures |
| 70 | |
| 71 | subroutine glDeleteTextures(n, textures) bind(C, name="fortty_glDeleteTextures") |
| 72 | import :: c_int |
| 73 | integer(c_int), value :: n |
| 74 | integer(c_int), intent(in) :: textures(*) |
| 75 | end subroutine glDeleteTextures |
| 76 | |
| 77 | subroutine glBindTexture(target, texture) bind(C, name="fortty_glBindTexture") |
| 78 | import :: c_int |
| 79 | integer(c_int), value :: target, texture |
| 80 | end subroutine glBindTexture |
| 81 | |
| 82 | subroutine glTexImage2D(target, level, internalformat, width, height, & |
| 83 | border, format, textype, data) bind(C, name="fortty_glTexImage2D") |
| 84 | import :: c_int, c_ptr |
| 85 | integer(c_int), value :: target, level, internalformat |
| 86 | integer(c_int), value :: width, height, border |
| 87 | integer(c_int), value :: format, textype |
| 88 | type(c_ptr), value :: data |
| 89 | end subroutine glTexImage2D |
| 90 | |
| 91 | subroutine glTexSubImage2D(target, level, xoffset, yoffset, width, height, & |
| 92 | format, textype, data) bind(C, name="fortty_glTexSubImage2D") |
| 93 | import :: c_int, c_ptr |
| 94 | integer(c_int), value :: target, level, xoffset, yoffset |
| 95 | integer(c_int), value :: width, height, format, textype |
| 96 | type(c_ptr), value :: data |
| 97 | end subroutine glTexSubImage2D |
| 98 | |
| 99 | subroutine glTexParameteri(target, pname, param) bind(C, name="fortty_glTexParameteri") |
| 100 | import :: c_int |
| 101 | integer(c_int), value :: target, pname, param |
| 102 | end subroutine glTexParameteri |
| 103 | |
| 104 | subroutine glPixelStorei(pname, param) bind(C, name="fortty_glPixelStorei") |
| 105 | import :: c_int |
| 106 | integer(c_int), value :: pname, param |
| 107 | end subroutine glPixelStorei |
| 108 | |
| 109 | subroutine glActiveTexture(texture) bind(C, name="fortty_glActiveTexture") |
| 110 | import :: c_int |
| 111 | integer(c_int), value :: texture |
| 112 | end subroutine glActiveTexture |
| 113 | |
| 114 | ! ============ Shader functions ============ |
| 115 | integer(c_int) function glCreateShader(shadertype) bind(C, name="fortty_glCreateShader") |
| 116 | import :: c_int |
| 117 | integer(c_int), value :: shadertype |
| 118 | end function glCreateShader |
| 119 | |
| 120 | subroutine glDeleteShader(shader) bind(C, name="fortty_glDeleteShader") |
| 121 | import :: c_int |
| 122 | integer(c_int), value :: shader |
| 123 | end subroutine glDeleteShader |
| 124 | |
| 125 | subroutine glShaderSource(shader, source) bind(C, name="fortty_glShaderSource") |
| 126 | import :: c_int, c_char |
| 127 | integer(c_int), value :: shader |
| 128 | character(kind=c_char), intent(in) :: source(*) |
| 129 | end subroutine glShaderSource |
| 130 | |
| 131 | subroutine glCompileShader(shader) bind(C, name="fortty_glCompileShader") |
| 132 | import :: c_int |
| 133 | integer(c_int), value :: shader |
| 134 | end subroutine glCompileShader |
| 135 | |
| 136 | integer(c_int) function glGetShaderCompileStatus(shader) & |
| 137 | bind(C, name="fortty_glGetShaderCompileStatus") |
| 138 | import :: c_int |
| 139 | integer(c_int), value :: shader |
| 140 | end function glGetShaderCompileStatus |
| 141 | |
| 142 | subroutine glGetShaderInfoLog(shader, log, maxlen) bind(C, name="fortty_glGetShaderInfoLog") |
| 143 | import :: c_int, c_char |
| 144 | integer(c_int), value :: shader, maxlen |
| 145 | character(kind=c_char), intent(out) :: log(*) |
| 146 | end subroutine glGetShaderInfoLog |
| 147 | |
| 148 | integer(c_int) function glCreateProgram() bind(C, name="fortty_glCreateProgram") |
| 149 | import :: c_int |
| 150 | end function glCreateProgram |
| 151 | |
| 152 | subroutine glDeleteProgram(program) bind(C, name="fortty_glDeleteProgram") |
| 153 | import :: c_int |
| 154 | integer(c_int), value :: program |
| 155 | end subroutine glDeleteProgram |
| 156 | |
| 157 | subroutine glAttachShader(program, shader) bind(C, name="fortty_glAttachShader") |
| 158 | import :: c_int |
| 159 | integer(c_int), value :: program, shader |
| 160 | end subroutine glAttachShader |
| 161 | |
| 162 | subroutine glLinkProgram(program) bind(C, name="fortty_glLinkProgram") |
| 163 | import :: c_int |
| 164 | integer(c_int), value :: program |
| 165 | end subroutine glLinkProgram |
| 166 | |
| 167 | integer(c_int) function glGetProgramLinkStatus(program) & |
| 168 | bind(C, name="fortty_glGetProgramLinkStatus") |
| 169 | import :: c_int |
| 170 | integer(c_int), value :: program |
| 171 | end function glGetProgramLinkStatus |
| 172 | |
| 173 | subroutine glGetProgramInfoLog(program, log, maxlen) bind(C, name="fortty_glGetProgramInfoLog") |
| 174 | import :: c_int, c_char |
| 175 | integer(c_int), value :: program, maxlen |
| 176 | character(kind=c_char), intent(out) :: log(*) |
| 177 | end subroutine glGetProgramInfoLog |
| 178 | |
| 179 | subroutine glUseProgram(program) bind(C, name="fortty_glUseProgram") |
| 180 | import :: c_int |
| 181 | integer(c_int), value :: program |
| 182 | end subroutine glUseProgram |
| 183 | |
| 184 | integer(c_int) function glGetUniformLocation(program, name) & |
| 185 | bind(C, name="fortty_glGetUniformLocation") |
| 186 | import :: c_int, c_char |
| 187 | integer(c_int), value :: program |
| 188 | character(kind=c_char), intent(in) :: name(*) |
| 189 | end function glGetUniformLocation |
| 190 | |
| 191 | subroutine glUniform1i(location, value) bind(C, name="fortty_glUniform1i") |
| 192 | import :: c_int |
| 193 | integer(c_int), value :: location, value |
| 194 | end subroutine glUniform1i |
| 195 | |
| 196 | subroutine glUniform1f(location, value) bind(C, name="fortty_glUniform1f") |
| 197 | import :: c_int, c_float |
| 198 | integer(c_int), value :: location |
| 199 | real(c_float), value :: value |
| 200 | end subroutine glUniform1f |
| 201 | |
| 202 | subroutine glUniform3f(location, v0, v1, v2) bind(C, name="fortty_glUniform3f") |
| 203 | import :: c_int, c_float |
| 204 | integer(c_int), value :: location |
| 205 | real(c_float), value :: v0, v1, v2 |
| 206 | end subroutine glUniform3f |
| 207 | |
| 208 | subroutine glUniform4f(location, v0, v1, v2, v3) bind(C, name="fortty_glUniform4f") |
| 209 | import :: c_int, c_float |
| 210 | integer(c_int), value :: location |
| 211 | real(c_float), value :: v0, v1, v2, v3 |
| 212 | end subroutine glUniform4f |
| 213 | |
| 214 | subroutine glUniformMatrix4fv(location, count, transpose, value) & |
| 215 | bind(C, name="fortty_glUniformMatrix4fv") |
| 216 | import :: c_int, c_float |
| 217 | integer(c_int), value :: location, count, transpose |
| 218 | real(c_float), intent(in) :: value(*) |
| 219 | end subroutine glUniformMatrix4fv |
| 220 | |
| 221 | ! ============ VAO/VBO functions ============ |
| 222 | subroutine glGenVertexArrays(n, arrays) bind(C, name="fortty_glGenVertexArrays") |
| 223 | import :: c_int |
| 224 | integer(c_int), value :: n |
| 225 | integer(c_int), intent(out) :: arrays(*) |
| 226 | end subroutine glGenVertexArrays |
| 227 | |
| 228 | subroutine glDeleteVertexArrays(n, arrays) bind(C, name="fortty_glDeleteVertexArrays") |
| 229 | import :: c_int |
| 230 | integer(c_int), value :: n |
| 231 | integer(c_int), intent(in) :: arrays(*) |
| 232 | end subroutine glDeleteVertexArrays |
| 233 | |
| 234 | subroutine glBindVertexArray(array) bind(C, name="fortty_glBindVertexArray") |
| 235 | import :: c_int |
| 236 | integer(c_int), value :: array |
| 237 | end subroutine glBindVertexArray |
| 238 | |
| 239 | subroutine glGenBuffers(n, buffers) bind(C, name="fortty_glGenBuffers") |
| 240 | import :: c_int |
| 241 | integer(c_int), value :: n |
| 242 | integer(c_int), intent(out) :: buffers(*) |
| 243 | end subroutine glGenBuffers |
| 244 | |
| 245 | subroutine glDeleteBuffers(n, buffers) bind(C, name="fortty_glDeleteBuffers") |
| 246 | import :: c_int |
| 247 | integer(c_int), value :: n |
| 248 | integer(c_int), intent(in) :: buffers(*) |
| 249 | end subroutine glDeleteBuffers |
| 250 | |
| 251 | subroutine glBindBuffer(target, buffer) bind(C, name="fortty_glBindBuffer") |
| 252 | import :: c_int |
| 253 | integer(c_int), value :: target, buffer |
| 254 | end subroutine glBindBuffer |
| 255 | |
| 256 | subroutine glBufferData(target, datasize, data, usage) bind(C, name="fortty_glBufferData") |
| 257 | import :: c_int, c_size_t, c_ptr |
| 258 | integer(c_int), value :: target |
| 259 | integer(c_size_t), value :: datasize |
| 260 | type(c_ptr), value :: data |
| 261 | integer(c_int), value :: usage |
| 262 | end subroutine glBufferData |
| 263 | |
| 264 | subroutine glBufferSubData(target, offset, datasize, data) bind(C, name="fortty_glBufferSubData") |
| 265 | import :: c_int, c_size_t, c_ptr |
| 266 | integer(c_int), value :: target |
| 267 | integer(c_size_t), value :: offset, datasize |
| 268 | type(c_ptr), value :: data |
| 269 | end subroutine glBufferSubData |
| 270 | |
| 271 | subroutine glBufferSubData_floats(target, offset, datasize, data) & |
| 272 | bind(C, name="fortty_glBufferSubData_floats") |
| 273 | import :: c_int, c_size_t, c_float |
| 274 | integer(c_int), value :: target |
| 275 | integer(c_size_t), value :: offset, datasize |
| 276 | real(c_float), intent(in) :: data(*) |
| 277 | end subroutine glBufferSubData_floats |
| 278 | |
| 279 | subroutine glVertexAttribPointer(index, vsize, vtype, normalized, stride, offset) & |
| 280 | bind(C, name="fortty_glVertexAttribPointer") |
| 281 | import :: c_int, c_size_t |
| 282 | integer(c_int), value :: index, vsize, vtype, normalized, stride |
| 283 | integer(c_size_t), value :: offset |
| 284 | end subroutine glVertexAttribPointer |
| 285 | |
| 286 | subroutine glEnableVertexAttribArray(index) bind(C, name="fortty_glEnableVertexAttribArray") |
| 287 | import :: c_int |
| 288 | integer(c_int), value :: index |
| 289 | end subroutine glEnableVertexAttribArray |
| 290 | |
| 291 | subroutine glDisableVertexAttribArray(index) bind(C, name="fortty_glDisableVertexAttribArray") |
| 292 | import :: c_int |
| 293 | integer(c_int), value :: index |
| 294 | end subroutine glDisableVertexAttribArray |
| 295 | |
| 296 | ! ============ Drawing functions ============ |
| 297 | subroutine glDrawArrays(mode, first, count) bind(C, name="fortty_glDrawArrays") |
| 298 | import :: c_int |
| 299 | integer(c_int), value :: mode, first, count |
| 300 | end subroutine glDrawArrays |
| 301 | |
| 302 | ! ============ State functions ============ |
| 303 | subroutine glEnable(cap) bind(C, name="fortty_glEnable") |
| 304 | import :: c_int |
| 305 | integer(c_int), value :: cap |
| 306 | end subroutine glEnable |
| 307 | |
| 308 | subroutine glDisable(cap) bind(C, name="fortty_glDisable") |
| 309 | import :: c_int |
| 310 | integer(c_int), value :: cap |
| 311 | end subroutine glDisable |
| 312 | |
| 313 | subroutine glBlendFunc(sfactor, dfactor) bind(C, name="fortty_glBlendFunc") |
| 314 | import :: c_int |
| 315 | integer(c_int), value :: sfactor, dfactor |
| 316 | end subroutine glBlendFunc |
| 317 | end interface |
| 318 | |
| 319 | end module gl_bindings |
| 320 |