Move guard where it belongs
[llpp/slowscroll.git] / lablGL / ml_glarray.c
blob275a262174833d3620133274f6999f2c8f15b9e0
2 #ifdef _WIN32
3 #include <wtypes.h>
4 #endif
5 #include <string.h>
6 #include <caml/misc.h>
7 #include <caml/mlvalues.h>
8 #include <caml/memory.h>
9 #include <caml/alloc.h>
10 #include <caml/config.h>
11 #ifdef __APPLE__
12 #include <OpenGL/gl.h>
13 #else
14 #include <GL/gl.h>
15 #endif
16 #include "ml_gl.h"
17 #include "gl_tags.h"
18 #include "raw_tags.h"
19 #include "ml_raw.h"
21 int ml_glSizeOfValue(value v) {
22 switch(v) {
23 case MLTAG_one: return(1);
24 case MLTAG_two: return(2);
25 case MLTAG_three: return(3);
26 case MLTAG_four: return(4);
27 default: ml_raise_gl("ml_glSizeOfValue: invalid size");
32 CAMLprim value ml_glEdgeFlagPointer(value raw)
34 glEdgeFlagPointer(0, (GLboolean*)Addr_raw(raw));
35 return Val_unit;
38 CAMLprim value ml_glTexCoordPointer(value size, value raw)
40 glTexCoordPointer (ml_glSizeOfValue(size),
41 GLenum_val(Kind_raw(raw)), 0, Void_raw(raw));
42 return Val_unit;
45 CAMLprim value ml_glColorPointer(value size, value raw)
47 glColorPointer (ml_glSizeOfValue(size),
48 GLenum_val(Kind_raw(raw)), 0, Void_raw(raw));
49 return Val_unit;
52 CAMLprim value ml_glIndexPointer(value raw)
54 glIndexPointer (GLenum_val(Kind_raw(raw)), 0, Void_raw(raw));
55 return Val_unit;
58 CAMLprim value ml_glNormalPointer(value raw)
60 glNormalPointer (GLenum_val(Kind_raw(raw)), 0, Void_raw(raw));
61 return Val_unit;
64 CAMLprim value ml_glVertexPointer(value size, value raw)
66 glVertexPointer (ml_glSizeOfValue(size),
67 GLenum_val(Kind_raw(raw)), 0, Void_raw(raw));
68 return Val_unit;
71 CAMLprim value ml_glEnableClientState(value kl)
73 GLenum a;
75 switch(kl) {
76 case MLTAG_edge_flag: a = GL_EDGE_FLAG_ARRAY; break;
77 case MLTAG_texture_coord: a = GL_TEXTURE_COORD_ARRAY; break;
78 case MLTAG_color: a = GL_COLOR_ARRAY; break;
79 case MLTAG_index: a = GL_INDEX_ARRAY; break;
80 case MLTAG_normal: a = GL_NORMAL_ARRAY; break;
81 case MLTAG_vertex: a = GL_VERTEX_ARRAY; break;
82 default: ml_raise_gl("ml_glEnableClientState: invalid array");
84 glEnableClientState(a);
85 return Val_unit;
88 CAMLprim value ml_glDisableClientState(value kl)
90 GLenum a;
92 switch(kl) {
93 case MLTAG_edge_flag: a = GL_EDGE_FLAG_ARRAY; break;
94 case MLTAG_texture_coord: a = GL_TEXTURE_COORD_ARRAY; break;
95 case MLTAG_color: a = GL_COLOR_ARRAY; break;
96 case MLTAG_index: a = GL_INDEX_ARRAY; break;
97 case MLTAG_normal: a = GL_NORMAL_ARRAY; break;
98 case MLTAG_vertex: a = GL_VERTEX_ARRAY; break;
99 default: ml_raise_gl("ml_glDisableClientState: invalid array");
101 glDisableClientState(a);
102 return Val_unit;
105 ML_1 (glArrayElement, Int_val);
106 ML_3 (glDrawArrays, GLenum_val, Int_val, Int_val);
108 CAMLprim value ml_glDrawElements(value mode, value count, value raw)
110 glDrawElements (GLenum_val(mode), Int_val(count),
111 GLenum_val(Kind_raw(raw)), Void_raw(raw));
112 return Val_unit;