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

SCM Repository

[sml3d] Annotation of /trunk/sml3d/src/raw-data/data-buffer-sig.sml
ViewVC logotype

Annotation of /trunk/sml3d/src/raw-data/data-buffer-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 839 - (view) (download)

1 : jhr 659 (* data-buffer-sig.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 John Reppy (http://cs.uchicago.edu/~jhr)
4 :     * All rights reserved.
5 :     *
6 :     * This is an interface to arrays of scalar types that are allocated in the C heap.
7 :     * It is designed to support the images, vertex arrays, draw buffers, etc.
8 :     *)
9 :    
10 :     signature DATA_BUFFER =
11 :     sig
12 :    
13 :     type float = Real32.real
14 :     type double = Real64.real
15 :    
16 :     type 'a buffer
17 :     type 'a buffer2 = ('a * 'a) buffer
18 :     type 'a buffer3 = ('a * 'a * 'a) buffer
19 :     type 'a buffer4 = ('a * 'a * 'a * 'a) buffer
20 :    
21 :     (* element types *)
22 :     type 'a ty
23 :     val ty2 : 'a ty -> ('a * 'a) ty
24 :     val ty3 : 'a ty -> ('a * 'a * 'a) ty
25 :     val ty4 : 'a ty -> ('a * 'a * 'a * 'a) ty
26 :     val tyb : Int8.int ty
27 :     val ty2b : (Int8.int * Int8.int) ty
28 :     val ty3b : (Int8.int * Int8.int * Int8.int) ty
29 :     val ty4b : (Int8.int * Int8.int * Int8.int * Int8.int) ty
30 :     val tyub : Word8.word ty
31 :     val ty2ub : (Word8.word * Word8.word) ty
32 :     val ty3ub : (Word8.word * Word8.word * Word8.word) ty
33 :     val ty4ub : (Word8.word * Word8.word * Word8.word * Word8.word) ty
34 :     val tys : Int16.int ty
35 :     val ty2s : (Int16.int * Int16.int) ty
36 :     val ty3s : (Int16.int * Int16.int * Int16.int) ty
37 :     val ty4s : (Int16.int * Int16.int * Int16.int * Int16.int) ty
38 :     val tyus : Word16.word ty
39 :     val ty2us : (Word16.word * Word16.word) ty
40 :     val ty3us : (Word16.word * Word16.word * Word16.word) ty
41 :     val ty4us : (Word16.word * Word16.word * Word16.word * Word16.word) ty
42 :     val tyi : Int32.int ty
43 :     val ty2i : (Int32.int * Int32.int) ty
44 :     val ty3i : (Int32.int * Int32.int * Int32.int) ty
45 :     val ty4i : (Int32.int * Int32.int * Int32.int * Int32.int) ty
46 :     val tyui : Word32.word ty
47 :     val ty2ui : (Word32.word * Word32.word) ty
48 :     val ty3ui : (Word32.word * Word32.word * Word32.word) ty
49 :     val ty4ui : (Word32.word * Word32.word * Word32.word * Word32.word) ty
50 :     val tyf : float ty
51 :     val ty2f : (float * float) ty
52 :     val ty3f : (float * float * float) ty
53 :     val ty4f : (float * float * float * float) ty
54 :     val tyd : double ty
55 :     val ty2d : (double * double) ty
56 :     val ty3d : (double * double * double) ty
57 :     val ty4d : (double * double * double * double) ty
58 :    
59 : jhr 777 (* a "cstruct" element type is a C struct type of some size and alignment; it is up to the
60 :     * user to get these right!. The only way to get/set values in a cstruct buffer is by using
61 :     * the C pointers. Note that the alignment must be a power of two!
62 :     *)
63 :     type cstruct
64 :     val tyStruct : {szb : C_Size.word, align : C_Size.word} -> cstruct ty
65 :    
66 : jhr 659 val sizeOf : 'a ty -> C_Size.word (* element size in bytes *)
67 :    
68 :     val make : {
69 : jhr 777 alloc : C_Size.word -> C_Pointer.t,
70 :     free : C_Pointer.t -> unit
71 : jhr 659 } -> ('a ty * int) -> 'a buffer
72 :    
73 :     val new : ('a ty * int) -> 'a buffer
74 :    
75 :     (* create a buffer from a pointer to C data. The first argument is the free
76 :     * function and the second argument is the element type/number of elements/
77 :     * data pointer triple.
78 :     *)
79 : jhr 777 val wrapCData : (C_Pointer.t -> unit) -> ('a ty * int * C_Pointer.t) -> 'a buffer
80 : jhr 659
81 :     val delete : 'a buffer -> unit
82 :     val valid : 'a buffer -> bool
83 :     val length : 'a buffer -> int
84 :     val typeOf : 'a buffer -> 'a ty (* element type *)
85 :    
86 :     (* monomorphic get/set operations on buffers *)
87 :     val getb : (Int8.int buffer * int) -> Int8.int
88 :     val setb : (Int8.int buffer * int * Int8.int) -> unit
89 :     val getub : (Word8.word buffer * int) -> Word8.word
90 :     val setub : (Word8.word buffer * int * Word8.word) -> unit
91 :     val gets : (Int16.int buffer * int) -> Int16.int
92 :     val sets : (Int16.int buffer * int * Int16.int) -> unit
93 :     val getus : (Word16.word buffer * int) -> Word16.word
94 :     val setus : (Word16.word buffer * int * Word16.word) -> unit
95 :     val geti : (Int32.int buffer * int) -> Int32.int
96 :     val seti : (Int32.int buffer * int * Int32.int) -> unit
97 :     val getui : (Word32.word buffer * int) -> Word32.word
98 :     val setui : (Word32.word buffer * int * Word32.word) -> unit
99 :     val getf : (float buffer * int) -> float
100 :     val setf : (float buffer * int * float) -> unit
101 :     val getd : (double buffer * int) -> double
102 :     val setd : (double buffer * int * double) -> unit
103 :    
104 :     val get2b : (Int8.int buffer2 * int) -> (Int8.int * Int8.int)
105 :     val set2b : (Int8.int buffer2 * int * (Int8.int * Int8.int)) -> unit
106 :     val get2ub : (Word8.word buffer2 * int) -> (Word8.word * Word8.word)
107 :     val set2ub : (Word8.word buffer2 * int * (Word8.word * Word8.word)) -> unit
108 :     val get2s : (Int16.int buffer2 * int) -> (Int16.int * Int16.int)
109 :     val set2s : (Int16.int buffer2 * int * (Int16.int * Int16.int)) -> unit
110 :     val get2us : (Word16.word buffer2 * int) -> (Word16.word * Word16.word)
111 :     val set2us : (Word16.word buffer2 * int * (Word16.word * Word16.word)) -> unit
112 :     val get2i : (Int32.int buffer2 * int) -> (Int32.int * Int32.int)
113 :     val set2i : (Int32.int buffer2 * int * (Int32.int * Int32.int)) -> unit
114 :     val get2ui : (Word32.word buffer2 * int) -> (Word32.word * Word32.word)
115 :     val set2ui : (Word32.word buffer2 * int * (Word32.word * Word32.word)) -> unit
116 :     val get2f : (float buffer2 * int) -> (float * float)
117 :     val set2f : (float buffer2 * int * (float * float)) -> unit
118 :     val get2d : (double buffer2 * int) -> (double * double)
119 :     val set2d : (double buffer2 * int * (double * double)) -> unit
120 :    
121 :     val get3b : (Int8.int buffer3 * int) -> (Int8.int * Int8.int * Int8.int)
122 :     val set3b : (Int8.int buffer3 * int * (Int8.int * Int8.int * Int8.int)) -> unit
123 :     val get3ub : (Word8.word buffer3 * int) -> (Word8.word * Word8.word * Word8.word)
124 :     val set3ub : (Word8.word buffer3 * int * (Word8.word * Word8.word * Word8.word)) -> unit
125 :     val get3s : (Int16.int buffer3 * int) -> (Int16.int * Int16.int * Int16.int)
126 :     val set3s : (Int16.int buffer3 * int * (Int16.int * Int16.int * Int16.int)) -> unit
127 :     val get3us : (Word16.word buffer3 * int) -> (Word16.word * Word16.word * Word16.word)
128 :     val set3us : (Word16.word buffer3 * int * (Word16.word * Word16.word * Word16.word)) -> unit
129 :     val get3i : (Int32.int buffer3 * int) -> (Int32.int * Int32.int * Int32.int)
130 :     val set3i : (Int32.int buffer3 * int * (Int32.int * Int32.int * Int32.int)) -> unit
131 :     val get3ui : (Word32.word buffer3 * int) -> (Word32.word * Word32.word * Word32.word)
132 :     val set3ui : (Word32.word buffer3 * int * (Word32.word * Word32.word * Word32.word)) -> unit
133 :     val get3f : (float buffer3 * int) -> (float * float * float)
134 :     val set3f : (float buffer3 * int * (float * float * float)) -> unit
135 :     val get3d : (double buffer3 * int) -> (double * double * double)
136 :     val set3d : (double buffer3 * int * (double * double * double)) -> unit
137 :    
138 :     val get4b : (Int8.int buffer4 * int) -> (Int8.int * Int8.int * Int8.int * Int8.int)
139 :     val set4b : (Int8.int buffer4 * int * (Int8.int * Int8.int * Int8.int * Int8.int)) -> unit
140 :     val get4ub : (Word8.word buffer4 * int) -> (Word8.word * Word8.word * Word8.word * Word8.word)
141 :     val set4ub : (Word8.word buffer4 * int * (Word8.word * Word8.word * Word8.word * Word8.word)) -> unit
142 :     val get4s : (Int16.int buffer4 * int) -> (Int16.int * Int16.int * Int16.int * Int16.int)
143 :     val set4s : (Int16.int buffer4 * int * (Int16.int * Int16.int * Int16.int * Int16.int)) -> unit
144 :     val get4us : (Word16.word buffer4 * int) -> (Word16.word * Word16.word * Word16.word * Word16.word)
145 :     val set4us : (Word16.word buffer4 * int * (Word16.word * Word16.word * Word16.word * Word16.word)) -> unit
146 :     val get4i : (Int32.int buffer4 * int) -> (Int32.int * Int32.int * Int32.int * Int32.int)
147 :     val set4i : (Int32.int buffer4 * int * (Int32.int * Int32.int * Int32.int * Int32.int)) -> unit
148 :     val get4ui : (Word32.word buffer4 * int) -> (Word32.word * Word32.word * Word32.word * Word32.word)
149 :     val set4ui : (Word32.word buffer4 * int * (Word32.word * Word32.word * Word32.word * Word32.word)) -> unit
150 :     val get4f : (float buffer4 * int) -> (float * float * float * float)
151 :     val set4f : (float buffer4 * int * (float * float * float * float)) -> unit
152 :     val get4d : (double buffer4 * int) -> (double * double * double * double)
153 :     val set4d : (double buffer4 * int * (double * double * double * double)) -> unit
154 :    
155 :     (* interpolation between buffers *)
156 :     val lerpf : {a : float buffer, t : float, b : float buffer, dst : float buffer} -> unit
157 :     val lerp2f : {a : float buffer2, t : float, b : float buffer2, dst : float buffer2} -> unit
158 :     val lerp3f : {a : float buffer3, t : float, b : float buffer3, dst : float buffer3} -> unit
159 :     val lerp4f : {a : float buffer4, t : float, b : float buffer4, dst : float buffer4} -> unit
160 :    
161 :     (*
162 :     (* return a flat view of a buffer *)
163 :     val flat2b : Int8.int buffer2 -> Int8.int buffer
164 :     val flat2ub : Word8.word buffer2 -> Word8.word buffer
165 :     val flat2s : Int16.int buffer2 -> Int16.int buffer
166 :     val flat2us : Word16.word buffer2 -> Word16.word buffer
167 :     val flat2i : Int32.int buffer2 -> Int32.int buffer
168 :     val flat2ui : Word32.word buffer2 -> Word32.word buffer
169 :     val flat2f : float buffer2 -> float buffer
170 :     val flat2d : double buffer2 -> double buffer
171 :    
172 :     val flat3b : Int8.int buffer3 -> Int8.int buffer
173 :     val flat3ub : Word8.word buffer3 -> Word8.word buffer
174 :     val flat3s : Int16.int buffer3 -> Int16.int buffer
175 :     val flat3us : Word16.word buffer3 -> Word16.word buffer
176 :     val flat3i : Int32.int buffer3 -> Int32.int buffer
177 :     val flat3ui : Word32.word buffer3 -> Word32.word buffer
178 :     val flat3f : float buffer3 -> float buffer
179 :     val flat3d : double buffer3 -> double buffer
180 :    
181 :     val flat4b : Int8.int buffer4 -> Int8.int buffer
182 :     val flat4ub : Word8.word buffer4 -> Word8.word buffer
183 :     val flat4s : Int16.int buffer4 -> Int16.int buffer
184 :     val flat4us : Word16.word buffer4 -> Word16.word buffer
185 :     val flat4i : Int32.int buffer4 -> Int32.int buffer
186 :     val flat4ui : Word32.word buffer4 -> Word32.word buffer
187 :     val flat4f : float buffer4 -> float buffer
188 :     val flat4d : double buffer4 -> double buffer
189 :     *)
190 :    
191 :     (* polymorphic operations on buffers *)
192 :     val get : 'a buffer * int -> 'a
193 :     val set : 'a buffer * int * 'a -> unit
194 :     val update : 'a buffer * int * ('a -> 'a) -> unit
195 :     val app : ('a -> unit) -> 'a buffer -> unit
196 :     val appi : (int * 'a -> unit) -> 'a buffer -> unit
197 : jhr 839 val foldl : ('a * 'b -> 'b) -> 'b -> 'a buffer -> 'b
198 :     val foldr : ('a * 'b -> 'b) -> 'b -> 'a buffer -> 'b
199 : jhr 659 val modify : ('a -> 'a) -> 'a buffer -> unit
200 :     val modifyi : (int * 'a -> 'a) -> 'a buffer -> unit
201 : jhr 664 val init : ('a buffer * (int -> 'a)) -> unit
202 : jhr 659
203 :     (* moving data in and out of SML *)
204 :     val mapToVector : 'a buffer * ('a -> 'b) -> 'b vector
205 :     val mapToArray : 'a buffer * ('a -> 'b) -> 'b array
206 :     val mapFromVector : ('a -> 'b) -> ('a vector * 'b buffer) -> unit
207 :     val mapFromArray : ('a -> 'b) -> ('a array * 'b buffer) -> unit
208 :     val copyFromVector : ('a vector * 'a buffer) -> unit
209 :     val copyFromArray : ('a array * 'a buffer) -> unit
210 :     val fromVector : 'a ty -> 'a vector -> 'a buffer
211 :     val fromArray : 'a ty -> 'a array -> 'a buffer
212 : jhr 664 val tabulate : ('a ty * int * (int -> 'a)) -> 'a buffer
213 : jhr 659
214 :     (* support for passing buffers to C code. Note that it is the responsibility of client code to
215 :     * make sure that data that is visibile to C is also retained by the SML heap.
216 :     *)
217 : jhr 777 val withPtr : ('a buffer * ({data : C_Pointer.t, szb : C_Size.word, elemSzb : C_Size.word} -> 'b)) -> 'b
218 : jhr 659 val touch : 'a buffer -> unit
219 :    
220 : jhr 779 (* operations on C struct buffers *)
221 :     structure CStruct : sig
222 : jhr 777
223 : jhr 779 (* apply an operation to a given element in a cstruct buffer *)
224 :     val withElemPtr : (cstruct buffer * (C_Pointer.t -> 'a)) -> int -> 'a
225 :    
226 :     (* apply an operation to every element of a cstruct buffer *)
227 :     val app : (C_Pointer.t -> unit) -> cstruct buffer -> unit
228 :     val appi : (int * C_Pointer.t -> unit) -> cstruct buffer -> unit
229 : jhr 839
230 :     val foldl : (C_Pointer.t * 'a -> 'a) -> 'a -> cstruct buffer -> 'a
231 :     val foldr : (C_Pointer.t * 'a -> 'a) -> 'a -> cstruct buffer -> 'a
232 : jhr 779 end
233 :    
234 : jhr 659 end

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