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

SCM Repository

[sml3d] View of /trunk/sml3d/src/openal/context.sml
ViewVC logotype

View of /trunk/sml3d/src/openal/context.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 884 - (download) (annotate)
Sat May 8 20:09:59 2010 UTC (9 years, 7 months ago) by jhr
File size: 1798 byte(s)
  Working on OpenAL implementation
(* context.sml
 *
 * COPYRIGHT (c) 2010 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * OpenAL context support
 *)

structure Context =
  struct
    local
      open ALTypes
      open ALConsts
      open ALFuncs
    in

    datatype context_attr
      = FREQUENCY of int	(* Frequency for mixing output buffer (Hz) *)
      | REFRESH of int		(* Refresh intervals (Hz) *)
      | SYNC of bool		(* Indicating a synchronous context *)
      | MONO_SOURCES of int	(* Number of requested mono sources *)
      | STEREO_SOURCES of int	(* Number of requested stereo sources *)

    local
    (* convert a list of context_attr values to a vector of integers in tag, value order. *)
      fun attrsToVec attrs = let
	    fun f (attr, attrs) = let
		  val (tag, value) = (case attr
			 of FREQUENCY hz => (ALC_FREQUENCY, hz)
			  | REFRESH hz => (ALC_REFRESH, hz)
			  | SYNC false => (ALC_SYNC, AL_FALSE)
			  | SYNC true => (ALC_SYNC, AL_TRUE)
			  | MONO_SOURCES n => (ALC_MONO_SOURCES, n)
			  | STEREO_SOURCES n => (ALC_STEREO_SOURCES, n)
			(* end case *))
		  in
		    tag::value::attrs
		  end
	    in
	      Vector.fromList (List.foldr f [0] attrs)
	    end
    fun optionPtr ptr = if (ptr = CPtr.null) then NONE else SOME ptr
    in
    fun create (dev, []) = optionPtr (alcCreateContext_np (dev, CPtr.null))
      | create (dev, attrs) = optionPtr (alcCreateContext (dev, attrsToVec attrs))

    fun getCurrent () = optionPtr (alcGetCurrentContext ())

    fun getDevice cxt = optionPtr (alcGetContextsDevice cxt)
    end

    fun makeCurrent cxt = let
	  val sts = Int8.toInt(alcMakeContextCurrent cxt)
	  in
	    (sts = AL_TRUE)
	  end

    val process = alcProcessContext
    val suspend = alcSuspendContext
    val destroy = alcDestroyContext

    end (* local *)
  end

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