Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] Annotation of /trunk/sml3d/src/sml3d/gl3/vertex.sml
ViewVC logotype

Annotation of /trunk/sml3d/src/sml3d/gl3/vertex.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1414 - (view) (download)

1 : jhr 1412 (* vertex.sml
2 :     *
3 :     * COPYRIGHT (c) 2014 The SML3d Project (http://sml3d.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * TODO: support for GL_INT_2_10_10_10_REV and GL_UNSIGNED_INT_2_10_10_10_REV
7 :     *)
8 :    
9 :     structure Vertex =
10 :     struct
11 :    
12 :     (* attribute locations *)
13 : jhr 1414 type attrib = GLuint.word
14 : jhr 1412
15 :     (* attribute locations can be specified as numeric values (corresponding to "layout"
16 :     * location specifications in shader programs). These functions convert between the
17 :     * abstract type and the concrete numeric representation.
18 :     *)
19 : jhr 1414 fun fromWord w = w
20 :     fun toWord w = w
21 : jhr 1412
22 : jhr 1414 fun maxVertexAttribs () = StateUtil.getInteger1 GLConsts.GL_MAX_VERTEX_ATTRIBS
23 : jhr 1412
24 :     (***** Vertex specification *****)
25 :    
26 :     (* specifying individual attributes [glVertexAttrib] *)
27 : jhr 1414 val attrib1s = GLFuncs2x.glVertexAttrib1s
28 :     val attrib1f = GLFuncs2x.glVertexAttrib1f
29 :     val attrib1d = GLFuncs2x.glVertexAttrib1d
30 :     val attribI1i = GLFuncs30.glVertexAttribI1i
31 :     val attribI1ui = GLFuncs30.glVertexAttribI1ui
32 :     val attrib2s = GLFuncs2x.glVertexAttrib2s
33 :     val attrib2f = GLFuncs2x.glVertexAttrib2f
34 :     val attrib2d = GLFuncs2x.glVertexAttrib2d
35 :     val attribI2i = GLFuncs30.glVertexAttribI2i
36 :     val attribI2ui = GLFuncs30.glVertexAttribI2ui
37 :     val attrib3s = GLFuncs2x.glVertexAttrib3s
38 :     val attrib3f = GLFuncs2x.glVertexAttrib3f
39 :     val attrib3d = GLFuncs2x.glVertexAttrib3d
40 :     val attribI3i = GLFuncs30.glVertexAttribI3i
41 :     val attribI3ui = GLFuncs30.glVertexAttribI3ui
42 :     val attrib4s = GLFuncs2x.glVertexAttrib4s
43 :     val attrib4f = GLFuncs2x.glVertexAttrib4f
44 :     val attrib4d = GLFuncs2x.glVertexAttrib4d
45 :     val attrib4Nub = GLFuncs2x.glVertexAttrib4Nub
46 :     val attribI4i = GLFuncs30.glVertexAttribI4i
47 :     val attribI4ui = GLFuncs30.glVertexAttribI4ui
48 : jhr 1412
49 :     (* packed attribute values were introduced in Open GL 3.3
50 :     eqtype packing
51 :     val INT_10_10_10_2 : packing
52 :     val UNSIGNED_INT_10_10_10_2 : packing
53 :    
54 :     val attribP1ui : attrib * packing * bool * uint -> unit
55 :     val attribP2ui : attrib * packing * bool * uint -> unit
56 :     val attribP3ui : attrib * packing * bool * uint -> unit
57 :     val attribP4ui : attrib * packing * bool * uint -> unit
58 :     *)
59 :    
60 :     (***** Vertex arrays *****)
61 :    
62 :     (* attribute arity phantom types *)
63 :     datatype one = ONE
64 :     datatype two = TWO
65 :     datatype three = THREE
66 :     datatype four = FOUR
67 :     datatype bgra = BGRA
68 :    
69 : jhr 1414 (* packed attribute values were introduced in Open GL 3.3
70 :     datatype int_2_10_10_10_rev = INT_2_10_10_10_REV
71 :     datatype uint_2_10_10_10_rev = UINT_2_10_10_10_REV
72 :     *)
73 : jhr 1412
74 : jhr 1414 datatype ('arity, 'ty) attrib_fmt = FMT of (GLint.int * GLenum.word)
75 :     datatype ('arity, 'ty) int_attrib_fmt = IFMT of (GLint.int * GLenum.word)
76 :    
77 : jhr 1412 (* attribute array formats *)
78 :     val array1b : (one, SML3dTypes.byte) int_attrib_fmt = IFMT(1, GLConsts.GL_BYTE)
79 :     val array1ub : (one, SML3dTypes.ubyte) int_attrib_fmt = IFMT(1, GLConsts.GL_UNSIGNED_BYTE)
80 :     val array1s : (one, SML3dTypes.short) int_attrib_fmt = IFMT(1, GLConsts.GL_SHORT)
81 :     val array1us : (one, SML3dTypes.ushort) int_attrib_fmt = IFMT(1, GLConsts.GL_UNSIGNED_SHORT)
82 :     val array1i : (one, SML3dTypes.int) int_attrib_fmt = IFMT(1, GLConsts.GL_INT)
83 :     val array1ui : (one, SML3dTypes.uint) int_attrib_fmt = IFMT(1, GLConsts.GL_UNSIGNED_INT)
84 :     val array1h : (one, SML3dTypes.half) attrib_fmt = FMT(1, GLConsts.GL_HALF_FLOAT)
85 :     val array1f : (one, SML3dTypes.float) attrib_fmt = FMT(1, GLConsts.GL_FLOAT)
86 :     val array1d : (one, SML3dTypes.double) attrib_fmt = FMT(1, GLConsts.GL_DOUBLE)
87 :    
88 :     val array2b : (two, SML3dTypes.byte) int_attrib_fmt = IFMT(2, GLConsts.GL_BYTE)
89 :     val array2ub : (two, SML3dTypes.ubyte) int_attrib_fmt = IFMT(2, GLConsts.GL_UNSIGNED_BYTE)
90 :     val array2s : (two, SML3dTypes.short) int_attrib_fmt = IFMT(2, GLConsts.GL_SHORT)
91 :     val array2us : (two, SML3dTypes.ushort) int_attrib_fmt = IFMT(2, GLConsts.GL_UNSIGNED_SHORT)
92 :     val array2i : (two, SML3dTypes.int) int_attrib_fmt = IFMT(2, GLConsts.GL_INT)
93 :     val array2ui : (two, SML3dTypes.uint) int_attrib_fmt = IFMT(2, GLConsts.GL_UNSIGNED_INT)
94 :     val array2h : (two, SML3dTypes.half) attrib_fmt = FMT(2, GLConsts.GL_HALF_FLOAT)
95 :     val array2f : (two, SML3dTypes.float) attrib_fmt = FMT(2, GLConsts.GL_FLOAT)
96 :     val array2d : (two, SML3dTypes.double) attrib_fmt = FMT(2, GLConsts.GL_DOUBLE)
97 :    
98 :     val array3b : (three, SML3dTypes.byte) int_attrib_fmt = IFMT(3, GLConsts.GL_BYTE)
99 :     val array3ub : (three, SML3dTypes.ubyte) int_attrib_fmt = IFMT(3, GLConsts.GL_UNSIGNED_BYTE)
100 :     val array3s : (three, SML3dTypes.short) int_attrib_fmt = IFMT(3, GLConsts.GL_SHORT)
101 :     val array3us : (three, SML3dTypes.ushort) int_attrib_fmt = IFMT(3, GLConsts.GL_UNSIGNED_SHORT)
102 :     val array3i : (three, SML3dTypes.int) int_attrib_fmt = IFMT(3, GLConsts.GL_INT)
103 :     val array3ui : (three, SML3dTypes.uint) int_attrib_fmt = IFMT(3, GLConsts.GL_UNSIGNED_INT)
104 :     val array3h : (three, SML3dTypes.half) attrib_fmt = FMT(3, GLConsts.GL_HALF_FLOAT)
105 :     val array3f : (three, SML3dTypes.float) attrib_fmt = FMT(3, GLConsts.GL_FLOAT)
106 :     val array3d : (three, SML3dTypes.double) attrib_fmt = FMT(3, GLConsts.GL_DOUBLE)
107 :    
108 :     val array4b : (four, SML3dTypes.byte) int_attrib_fmt = IFMT(4, GLConsts.GL_BYTE)
109 :     val array4ub : (four, SML3dTypes.ubyte) int_attrib_fmt = IFMT(4, GLConsts.GL_UNSIGNED_BYTE)
110 :     val array4s : (four, SML3dTypes.short) int_attrib_fmt = IFMT(4, GLConsts.GL_SHORT)
111 :     val array4us : (four, SML3dTypes.ushort) int_attrib_fmt = IFMT(4, GLConsts.GL_UNSIGNED_SHORT)
112 :     val array4i : (four, SML3dTypes.int) int_attrib_fmt = IFMT(4, GLConsts.GL_INT)
113 :     val array4ui : (four, SML3dTypes.uint) int_attrib_fmt = IFMT(4, GLConsts.GL_UNSIGNED_INT)
114 :     val array4h : (four, SML3dTypes.half) attrib_fmt = FMT(4, GLConsts.GL_HALF_FLOAT)
115 :     val array4f : (four, SML3dTypes.float) attrib_fmt = FMT(4, GLConsts.GL_FLOAT)
116 :     val array4d : (four, SML3dTypes.double) attrib_fmt = FMT(4, GLConsts.GL_DOUBLE)
117 :    
118 :     (* arrays with reverse-order components *)
119 :     val arrayBGRAub : (bgra, SML3dTypes.ubyte) int_attrib_fmt = IFMT(GLenum.toIntX GLConsts.GL_BGRA, GLConsts.GL_UNSIGNED_BYTE)
120 : jhr 1414 (* packed attribute values were introduced in Open GL 3.3
121 :     val arrayBGRApi : (bgra, int_2_10_10_10_rev) attrib_fmt = FMT(GLenum.toIntX GLConsts.GL_BGRA, GLConsts.GL_INT_2_10_10_10_REV)
122 :     val arrayBGRApui : (bgra, uint_2_10_10_10_rev) attrib_fmt = FMT(GLenum.toIntX GLConsts.GL_BGRA, GLConsts.GL_UNSIGNED_INT_2_10_10_10_REV)
123 :     *)
124 : jhr 1412
125 :     (* specifying floating-point attributes. The bool argument specifies whether integer arguments
126 :     * should be mapped to a normalized range ([-1..1] for signed values and [0..1] for unsigned).
127 :     *)
128 : jhr 1414 fun attribFltArray (attrib, FMT(arity, ty)) =
129 :     GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, GLConsts.GL_FALSE, 0, 0)
130 :     fun attribArray (attrib, normalize, IFMT(arity, ty)) =
131 :     GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, if normalize then GLConsts.GL_TRUE else GLConsts.GL_FALSE, 0, 0)
132 :     fun attribIntArray (attrib, IFMT(arity, ty)) =
133 :     GLFuncs30.glVertexAttribIPointer (attrib, arity, ty, 0, 0)
134 : jhr 1412
135 :     (* like the previous three functions, but with stride and offset info too *)
136 : jhr 1414 fun attribFltArray' (attrib, FMT(arity, ty), stride, offset) =
137 :     GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, GLConsts.GL_FALSE, stride, offset)
138 :     fun attribArray' (attrib, normalize, IFMT(arity, ty), stride, offset) =
139 :     GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, if normalize then GLConsts.GL_TRUE else GLConsts.GL_FALSE, stride, offset)
140 :     fun attribIntArray' (attrib, IFMT(arity, ty), stride, offset) =
141 :     GLFuncs30.glVertexAttribIPointer (attrib, arity, ty, stride, offset)
142 : jhr 1412
143 : jhr 1414 val enableArray = GLFuncs2x.glEnableVertexAttribArray
144 :     val disableArray = GLFuncs2x.glDisableVertexAttribArray
145 :    
146 : jhr 1412 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0