| 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 | ! Scissor test constant |
| 47 | integer(c_int), parameter :: GL_SCISSOR_TEST = int(Z'0C11', c_int) |
| 48 | |
| 49 | ! Interface to C wrapper functions (in gl_loader.c) |
| 50 | interface |
| 51 | ! ============ Basic functions ============ |
| 52 | subroutine glViewport(x, y, width, height) bind(C, name="fortty_glViewport") |
| 53 | import :: c_int |
| 54 | integer(c_int), value :: x, y, width, height |
| 55 | end subroutine glViewport |
| 56 | |
| 57 | subroutine glClear(mask) bind(C, name="fortty_glClear") |
| 58 | import :: c_int |
| 59 | integer(c_int), value :: mask |
| 60 | end subroutine glClear |
| 61 | |
| 62 | subroutine glClearColor(red, green, blue, alpha) bind(C, name="fortty_glClearColor") |
| 63 | import :: c_float |
| 64 | real(c_float), value :: red, green, blue, alpha |
| 65 | end subroutine glClearColor |
| 66 | |
| 67 | ! ============ Texture functions ============ |
| 68 | subroutine glGenTextures(n, textures) bind(C, name="fortty_glGenTextures") |
| 69 | import :: c_int |
| 70 | integer(c_int), value :: n |
| 71 | integer(c_int), intent(out) :: textures(*) |
| 72 | end subroutine glGenTextures |
| 73 | |
| 74 | subroutine glDeleteTextures(n, textures) bind(C, name="fortty_glDeleteTextures") |
| 75 | import :: c_int |
| 76 | integer(c_int), value :: n |
| 77 | integer(c_int), intent(in) :: textures(*) |
| 78 | end subroutine glDeleteTextures |
| 79 | |
| 80 | subroutine glBindTexture(target, texture) bind(C, name="fortty_glBindTexture") |
| 81 | import :: c_int |
| 82 | integer(c_int), value :: target, texture |
| 83 | end subroutine glBindTexture |
| 84 | |
| 85 | subroutine glTexImage2D(target, level, internalformat, width, height, & |
| 86 | border, format, textype, data) bind(C, name="fortty_glTexImage2D") |
| 87 | import :: c_int, c_ptr |
| 88 | integer(c_int), value :: target, level, internalformat |
| 89 | integer(c_int), value :: width, height, border |
| 90 | integer(c_int), value :: format, textype |
| 91 | type(c_ptr), value :: data |
| 92 | end subroutine glTexImage2D |
| 93 | |
| 94 | subroutine glTexSubImage2D(target, level, xoffset, yoffset, width, height, & |
| 95 | format, textype, data) bind(C, name="fortty_glTexSubImage2D") |
| 96 | import :: c_int, c_ptr |
| 97 | integer(c_int), value :: target, level, xoffset, yoffset |
| 98 | integer(c_int), value :: width, height, format, textype |
| 99 | type(c_ptr), value :: data |
| 100 | end subroutine glTexSubImage2D |
| 101 | |
| 102 | subroutine glTexParameteri(target, pname, param) bind(C, name="fortty_glTexParameteri") |
| 103 | import :: c_int |
| 104 | integer(c_int), value :: target, pname, param |
| 105 | end subroutine glTexParameteri |
| 106 | |
| 107 | subroutine glPixelStorei(pname, param) bind(C, name="fortty_glPixelStorei") |
| 108 | import :: c_int |
| 109 | integer(c_int), value :: pname, param |
| 110 | end subroutine glPixelStorei |
| 111 | |
| 112 | subroutine glActiveTexture(texture) bind(C, name="fortty_glActiveTexture") |
| 113 | import :: c_int |
| 114 | integer(c_int), value :: texture |
| 115 | end subroutine glActiveTexture |
| 116 | |
| 117 | ! ============ Shader functions ============ |
| 118 | integer(c_int) function glCreateShader(shadertype) bind(C, name="fortty_glCreateShader") |
| 119 | import :: c_int |
| 120 | integer(c_int), value :: shadertype |
| 121 | end function glCreateShader |
| 122 | |
| 123 | subroutine glDeleteShader(shader) bind(C, name="fortty_glDeleteShader") |
| 124 | import :: c_int |
| 125 | integer(c_int), value :: shader |
| 126 | end subroutine glDeleteShader |
| 127 | |
| 128 | subroutine glShaderSource(shader, source) bind(C, name="fortty_glShaderSource") |
| 129 | import :: c_int, c_char |
| 130 | integer(c_int), value :: shader |
| 131 | character(kind=c_char), intent(in) :: source(*) |
| 132 | end subroutine glShaderSource |
| 133 | |
| 134 | subroutine glCompileShader(shader) bind(C, name="fortty_glCompileShader") |
| 135 | import :: c_int |
| 136 | integer(c_int), value :: shader |
| 137 | end subroutine glCompileShader |
| 138 | |
| 139 | integer(c_int) function glGetShaderCompileStatus(shader) & |
| 140 | bind(C, name="fortty_glGetShaderCompileStatus") |
| 141 | import :: c_int |
| 142 | integer(c_int), value :: shader |
| 143 | end function glGetShaderCompileStatus |
| 144 | |
| 145 | subroutine glGetShaderInfoLog(shader, log, maxlen) bind(C, name="fortty_glGetShaderInfoLog") |
| 146 | import :: c_int, c_char |
| 147 | integer(c_int), value :: shader, maxlen |
| 148 | character(kind=c_char), intent(out) :: log(*) |
| 149 | end subroutine glGetShaderInfoLog |
| 150 | |
| 151 | integer(c_int) function glCreateProgram() bind(C, name="fortty_glCreateProgram") |
| 152 | import :: c_int |
| 153 | end function glCreateProgram |
| 154 | |
| 155 | subroutine glDeleteProgram(program) bind(C, name="fortty_glDeleteProgram") |
| 156 | import :: c_int |
| 157 | integer(c_int), value :: program |
| 158 | end subroutine glDeleteProgram |
| 159 | |
| 160 | subroutine glAttachShader(program, shader) bind(C, name="fortty_glAttachShader") |
| 161 | import :: c_int |
| 162 | integer(c_int), value :: program, shader |
| 163 | end subroutine glAttachShader |
| 164 | |
| 165 | subroutine glLinkProgram(program) bind(C, name="fortty_glLinkProgram") |
| 166 | import :: c_int |
| 167 | integer(c_int), value :: program |
| 168 | end subroutine glLinkProgram |
| 169 | |
| 170 | integer(c_int) function glGetProgramLinkStatus(program) & |
| 171 | bind(C, name="fortty_glGetProgramLinkStatus") |
| 172 | import :: c_int |
| 173 | integer(c_int), value :: program |
| 174 | end function glGetProgramLinkStatus |
| 175 | |
| 176 | subroutine glGetProgramInfoLog(program, log, maxlen) bind(C, name="fortty_glGetProgramInfoLog") |
| 177 | import :: c_int, c_char |
| 178 | integer(c_int), value :: program, maxlen |
| 179 | character(kind=c_char), intent(out) :: log(*) |
| 180 | end subroutine glGetProgramInfoLog |
| 181 | |
| 182 | subroutine glUseProgram(program) bind(C, name="fortty_glUseProgram") |
| 183 | import :: c_int |
| 184 | integer(c_int), value :: program |
| 185 | end subroutine glUseProgram |
| 186 | |
| 187 | integer(c_int) function glGetUniformLocation(program, name) & |
| 188 | bind(C, name="fortty_glGetUniformLocation") |
| 189 | import :: c_int, c_char |
| 190 | integer(c_int), value :: program |
| 191 | character(kind=c_char), intent(in) :: name(*) |
| 192 | end function glGetUniformLocation |
| 193 | |
| 194 | subroutine glUniform1i(location, value) bind(C, name="fortty_glUniform1i") |
| 195 | import :: c_int |
| 196 | integer(c_int), value :: location, value |
| 197 | end subroutine glUniform1i |
| 198 | |
| 199 | subroutine glUniform1f(location, value) bind(C, name="fortty_glUniform1f") |
| 200 | import :: c_int, c_float |
| 201 | integer(c_int), value :: location |
| 202 | real(c_float), value :: value |
| 203 | end subroutine glUniform1f |
| 204 | |
| 205 | subroutine glUniform3f(location, v0, v1, v2) bind(C, name="fortty_glUniform3f") |
| 206 | import :: c_int, c_float |
| 207 | integer(c_int), value :: location |
| 208 | real(c_float), value :: v0, v1, v2 |
| 209 | end subroutine glUniform3f |
| 210 | |
| 211 | subroutine glUniform4f(location, v0, v1, v2, v3) bind(C, name="fortty_glUniform4f") |
| 212 | import :: c_int, c_float |
| 213 | integer(c_int), value :: location |
| 214 | real(c_float), value :: v0, v1, v2, v3 |
| 215 | end subroutine glUniform4f |
| 216 | |
| 217 | subroutine glUniformMatrix4fv(location, count, transpose, value) & |
| 218 | bind(C, name="fortty_glUniformMatrix4fv") |
| 219 | import :: c_int, c_float |
| 220 | integer(c_int), value :: location, count, transpose |
| 221 | real(c_float), intent(in) :: value(*) |
| 222 | end subroutine glUniformMatrix4fv |
| 223 | |
| 224 | ! ============ VAO/VBO functions ============ |
| 225 | subroutine glGenVertexArrays(n, arrays) bind(C, name="fortty_glGenVertexArrays") |
| 226 | import :: c_int |
| 227 | integer(c_int), value :: n |
| 228 | integer(c_int), intent(out) :: arrays(*) |
| 229 | end subroutine glGenVertexArrays |
| 230 | |
| 231 | subroutine glDeleteVertexArrays(n, arrays) bind(C, name="fortty_glDeleteVertexArrays") |
| 232 | import :: c_int |
| 233 | integer(c_int), value :: n |
| 234 | integer(c_int), intent(in) :: arrays(*) |
| 235 | end subroutine glDeleteVertexArrays |
| 236 | |
| 237 | subroutine glBindVertexArray(array) bind(C, name="fortty_glBindVertexArray") |
| 238 | import :: c_int |
| 239 | integer(c_int), value :: array |
| 240 | end subroutine glBindVertexArray |
| 241 | |
| 242 | subroutine glGenBuffers(n, buffers) bind(C, name="fortty_glGenBuffers") |
| 243 | import :: c_int |
| 244 | integer(c_int), value :: n |
| 245 | integer(c_int), intent(out) :: buffers(*) |
| 246 | end subroutine glGenBuffers |
| 247 | |
| 248 | subroutine glDeleteBuffers(n, buffers) bind(C, name="fortty_glDeleteBuffers") |
| 249 | import :: c_int |
| 250 | integer(c_int), value :: n |
| 251 | integer(c_int), intent(in) :: buffers(*) |
| 252 | end subroutine glDeleteBuffers |
| 253 | |
| 254 | subroutine glBindBuffer(target, buffer) bind(C, name="fortty_glBindBuffer") |
| 255 | import :: c_int |
| 256 | integer(c_int), value :: target, buffer |
| 257 | end subroutine glBindBuffer |
| 258 | |
| 259 | subroutine glBufferData(target, datasize, data, usage) bind(C, name="fortty_glBufferData") |
| 260 | import :: c_int, c_size_t, c_ptr |
| 261 | integer(c_int), value :: target |
| 262 | integer(c_size_t), value :: datasize |
| 263 | type(c_ptr), value :: data |
| 264 | integer(c_int), value :: usage |
| 265 | end subroutine glBufferData |
| 266 | |
| 267 | subroutine glBufferSubData(target, offset, datasize, data) bind(C, name="fortty_glBufferSubData") |
| 268 | import :: c_int, c_size_t, c_ptr |
| 269 | integer(c_int), value :: target |
| 270 | integer(c_size_t), value :: offset, datasize |
| 271 | type(c_ptr), value :: data |
| 272 | end subroutine glBufferSubData |
| 273 | |
| 274 | subroutine glBufferSubData_floats(target, offset, datasize, data) & |
| 275 | bind(C, name="fortty_glBufferSubData_floats") |
| 276 | import :: c_int, c_size_t, c_float |
| 277 | integer(c_int), value :: target |
| 278 | integer(c_size_t), value :: offset, datasize |
| 279 | real(c_float), intent(in) :: data(*) |
| 280 | end subroutine glBufferSubData_floats |
| 281 | |
| 282 | subroutine glVertexAttribPointer(index, vsize, vtype, normalized, stride, offset) & |
| 283 | bind(C, name="fortty_glVertexAttribPointer") |
| 284 | import :: c_int, c_size_t |
| 285 | integer(c_int), value :: index, vsize, vtype, normalized, stride |
| 286 | integer(c_size_t), value :: offset |
| 287 | end subroutine glVertexAttribPointer |
| 288 | |
| 289 | subroutine glEnableVertexAttribArray(index) bind(C, name="fortty_glEnableVertexAttribArray") |
| 290 | import :: c_int |
| 291 | integer(c_int), value :: index |
| 292 | end subroutine glEnableVertexAttribArray |
| 293 | |
| 294 | subroutine glDisableVertexAttribArray(index) bind(C, name="fortty_glDisableVertexAttribArray") |
| 295 | import :: c_int |
| 296 | integer(c_int), value :: index |
| 297 | end subroutine glDisableVertexAttribArray |
| 298 | |
| 299 | ! ============ Drawing functions ============ |
| 300 | subroutine glDrawArrays(mode, first, count) bind(C, name="fortty_glDrawArrays") |
| 301 | import :: c_int |
| 302 | integer(c_int), value :: mode, first, count |
| 303 | end subroutine glDrawArrays |
| 304 | |
| 305 | ! ============ State functions ============ |
| 306 | subroutine glEnable(cap) bind(C, name="fortty_glEnable") |
| 307 | import :: c_int |
| 308 | integer(c_int), value :: cap |
| 309 | end subroutine glEnable |
| 310 | |
| 311 | subroutine glDisable(cap) bind(C, name="fortty_glDisable") |
| 312 | import :: c_int |
| 313 | integer(c_int), value :: cap |
| 314 | end subroutine glDisable |
| 315 | |
| 316 | subroutine glBlendFunc(sfactor, dfactor) bind(C, name="fortty_glBlendFunc") |
| 317 | import :: c_int |
| 318 | integer(c_int), value :: sfactor, dfactor |
| 319 | end subroutine glBlendFunc |
| 320 | |
| 321 | subroutine glScissor(x, y, width, height) bind(C, name="fortty_glScissor") |
| 322 | import :: c_int |
| 323 | integer(c_int), value :: x, y, width, height |
| 324 | end subroutine glScissor |
| 325 | end interface |
| 326 | |
| 327 | end module gl_bindings |
| 328 |