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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1414 - (download) (annotate)
Mon Apr 14 22:49:17 2014 UTC (4 years, 10 months ago) by jhr
File size: 7755 byte(s)
  Vertex attributes for OpenGL 3.2 core
(* vertex.sml
 *
 * COPYRIGHT (c) 2014 The SML3d Project (http://sml3d.cs.uchicago.edu)
 * All rights reserved.
 *
 * TODO: support for GL_INT_2_10_10_10_REV and GL_UNSIGNED_INT_2_10_10_10_REV
 *)

structure Vertex =
  struct

  (* attribute locations *)
    type attrib = GLuint.word

  (* attribute locations can be specified as numeric values (corresponding to "layout"
   * location specifications in shader programs).  These functions convert between the
   * abstract type and the concrete numeric representation.
   *)
    fun fromWord w = w
    fun toWord w = w

    fun maxVertexAttribs () = StateUtil.getInteger1 GLConsts.GL_MAX_VERTEX_ATTRIBS

  (***** Vertex specification *****)

  (* specifying individual attributes [glVertexAttrib] *)
    val attrib1s   = GLFuncs2x.glVertexAttrib1s
    val attrib1f   = GLFuncs2x.glVertexAttrib1f
    val attrib1d   = GLFuncs2x.glVertexAttrib1d
    val attribI1i  = GLFuncs30.glVertexAttribI1i
    val attribI1ui = GLFuncs30.glVertexAttribI1ui
    val attrib2s   = GLFuncs2x.glVertexAttrib2s
    val attrib2f   = GLFuncs2x.glVertexAttrib2f
    val attrib2d   = GLFuncs2x.glVertexAttrib2d
    val attribI2i  = GLFuncs30.glVertexAttribI2i
    val attribI2ui = GLFuncs30.glVertexAttribI2ui
    val attrib3s   = GLFuncs2x.glVertexAttrib3s
    val attrib3f   = GLFuncs2x.glVertexAttrib3f
    val attrib3d   = GLFuncs2x.glVertexAttrib3d
    val attribI3i  = GLFuncs30.glVertexAttribI3i
    val attribI3ui = GLFuncs30.glVertexAttribI3ui
    val attrib4s   = GLFuncs2x.glVertexAttrib4s
    val attrib4f   = GLFuncs2x.glVertexAttrib4f
    val attrib4d   = GLFuncs2x.glVertexAttrib4d
    val attrib4Nub = GLFuncs2x.glVertexAttrib4Nub
    val attribI4i  = GLFuncs30.glVertexAttribI4i
    val attribI4ui = GLFuncs30.glVertexAttribI4ui

(* packed attribute values were introduced in Open GL 3.3
    eqtype packing
    val INT_10_10_10_2 : packing
    val UNSIGNED_INT_10_10_10_2 : packing

    val attribP1ui : attrib * packing * bool * uint -> unit
    val attribP2ui : attrib * packing * bool * uint -> unit
    val attribP3ui : attrib * packing * bool * uint -> unit
    val attribP4ui : attrib * packing * bool * uint -> unit
*)

  (***** Vertex arrays *****)

  (* attribute arity phantom types *)
    datatype one = ONE
    datatype two = TWO
    datatype three = THREE
    datatype four = FOUR
    datatype bgra = BGRA

(* packed attribute values were introduced in Open GL 3.3
    datatype int_2_10_10_10_rev = INT_2_10_10_10_REV
    datatype uint_2_10_10_10_rev = UINT_2_10_10_10_REV
*)

    datatype ('arity, 'ty) attrib_fmt = FMT of (GLint.int * GLenum.word)
    datatype ('arity, 'ty) int_attrib_fmt = IFMT of (GLint.int * GLenum.word)

  (* attribute array formats *)
    val array1b  : (one, SML3dTypes.byte) int_attrib_fmt = IFMT(1, GLConsts.GL_BYTE)
    val array1ub : (one, SML3dTypes.ubyte) int_attrib_fmt = IFMT(1, GLConsts.GL_UNSIGNED_BYTE)
    val array1s  : (one, SML3dTypes.short) int_attrib_fmt = IFMT(1, GLConsts.GL_SHORT)
    val array1us : (one, SML3dTypes.ushort) int_attrib_fmt = IFMT(1, GLConsts.GL_UNSIGNED_SHORT)
    val array1i  : (one, SML3dTypes.int) int_attrib_fmt = IFMT(1, GLConsts.GL_INT)
    val array1ui : (one, SML3dTypes.uint) int_attrib_fmt = IFMT(1, GLConsts.GL_UNSIGNED_INT)
    val array1h  : (one, SML3dTypes.half) attrib_fmt = FMT(1, GLConsts.GL_HALF_FLOAT)
    val array1f  : (one, SML3dTypes.float) attrib_fmt = FMT(1, GLConsts.GL_FLOAT)
    val array1d  : (one, SML3dTypes.double) attrib_fmt = FMT(1, GLConsts.GL_DOUBLE)

    val array2b  : (two, SML3dTypes.byte) int_attrib_fmt = IFMT(2, GLConsts.GL_BYTE)
    val array2ub : (two, SML3dTypes.ubyte) int_attrib_fmt = IFMT(2, GLConsts.GL_UNSIGNED_BYTE)
    val array2s  : (two, SML3dTypes.short) int_attrib_fmt = IFMT(2, GLConsts.GL_SHORT)
    val array2us : (two, SML3dTypes.ushort) int_attrib_fmt = IFMT(2, GLConsts.GL_UNSIGNED_SHORT)
    val array2i  : (two, SML3dTypes.int) int_attrib_fmt = IFMT(2, GLConsts.GL_INT)
    val array2ui : (two, SML3dTypes.uint) int_attrib_fmt = IFMT(2, GLConsts.GL_UNSIGNED_INT)
    val array2h  : (two, SML3dTypes.half) attrib_fmt = FMT(2, GLConsts.GL_HALF_FLOAT)
    val array2f  : (two, SML3dTypes.float) attrib_fmt = FMT(2, GLConsts.GL_FLOAT)
    val array2d  : (two, SML3dTypes.double) attrib_fmt = FMT(2, GLConsts.GL_DOUBLE)

    val array3b  : (three, SML3dTypes.byte) int_attrib_fmt = IFMT(3, GLConsts.GL_BYTE)
    val array3ub : (three, SML3dTypes.ubyte) int_attrib_fmt = IFMT(3, GLConsts.GL_UNSIGNED_BYTE)
    val array3s  : (three, SML3dTypes.short) int_attrib_fmt = IFMT(3, GLConsts.GL_SHORT)
    val array3us : (three, SML3dTypes.ushort) int_attrib_fmt = IFMT(3, GLConsts.GL_UNSIGNED_SHORT)
    val array3i  : (three, SML3dTypes.int) int_attrib_fmt = IFMT(3, GLConsts.GL_INT)
    val array3ui : (three, SML3dTypes.uint) int_attrib_fmt = IFMT(3, GLConsts.GL_UNSIGNED_INT)
    val array3h  : (three, SML3dTypes.half) attrib_fmt = FMT(3, GLConsts.GL_HALF_FLOAT)
    val array3f  : (three, SML3dTypes.float) attrib_fmt = FMT(3, GLConsts.GL_FLOAT)
    val array3d  : (three, SML3dTypes.double) attrib_fmt = FMT(3, GLConsts.GL_DOUBLE)

    val array4b  : (four, SML3dTypes.byte) int_attrib_fmt = IFMT(4, GLConsts.GL_BYTE)
    val array4ub : (four, SML3dTypes.ubyte) int_attrib_fmt = IFMT(4, GLConsts.GL_UNSIGNED_BYTE)
    val array4s  : (four, SML3dTypes.short) int_attrib_fmt = IFMT(4, GLConsts.GL_SHORT)
    val array4us : (four, SML3dTypes.ushort) int_attrib_fmt = IFMT(4, GLConsts.GL_UNSIGNED_SHORT)
    val array4i  : (four, SML3dTypes.int) int_attrib_fmt = IFMT(4, GLConsts.GL_INT)
    val array4ui : (four, SML3dTypes.uint) int_attrib_fmt = IFMT(4, GLConsts.GL_UNSIGNED_INT)
    val array4h  : (four, SML3dTypes.half) attrib_fmt = FMT(4, GLConsts.GL_HALF_FLOAT)
    val array4f  : (four, SML3dTypes.float) attrib_fmt = FMT(4, GLConsts.GL_FLOAT)
    val array4d  : (four, SML3dTypes.double) attrib_fmt = FMT(4, GLConsts.GL_DOUBLE)

  (* arrays with reverse-order components *)
    val arrayBGRAub : (bgra, SML3dTypes.ubyte) int_attrib_fmt = IFMT(GLenum.toIntX GLConsts.GL_BGRA, GLConsts.GL_UNSIGNED_BYTE)
(* packed attribute values were introduced in Open GL 3.3
    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)
    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)
*)

  (* specifying floating-point attributes.  The bool argument specifies whether integer arguments
   * should be mapped to a normalized range ([-1..1] for signed values and [0..1] for unsigned).
   *)
    fun attribFltArray (attrib, FMT(arity, ty)) =
	  GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, GLConsts.GL_FALSE, 0, 0)
    fun attribArray (attrib, normalize, IFMT(arity, ty)) =
	  GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, if normalize then GLConsts.GL_TRUE else GLConsts.GL_FALSE, 0, 0)
    fun attribIntArray (attrib, IFMT(arity, ty)) =
	  GLFuncs30.glVertexAttribIPointer (attrib, arity, ty, 0, 0)

  (* like the previous three functions, but with stride and offset info too *)
    fun attribFltArray' (attrib, FMT(arity, ty), stride, offset) =
	  GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, GLConsts.GL_FALSE, stride, offset)
    fun attribArray' (attrib, normalize, IFMT(arity, ty), stride, offset) =
	  GLFuncs2x.glVertexAttribPointer (attrib, arity, ty, if normalize then GLConsts.GL_TRUE else GLConsts.GL_FALSE, stride, offset)
    fun attribIntArray' (attrib, IFMT(arity, ty), stride, offset) =
	  GLFuncs30.glVertexAttribIPointer (attrib, arity, ty, stride, offset)

    val enableArray = GLFuncs2x.glEnableVertexAttribArray
    val disableArray = GLFuncs2x.glDisableVertexAttribArray

  end

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