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

SCM Repository

[sml3d] View of /trunk/sml3d/src/base/opengl/fbo.sml
ViewVC logotype

View of /trunk/sml3d/src/base/opengl/fbo.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 454 - (download) (annotate)
Mon May 18 23:19:14 2009 UTC (10 years, 3 months ago) by jhr
File size: 5896 byte(s)
  Working on FBO support
(* fbo.sml
 *
 * COPYRIGHT (c) 2009 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * Frame-buffer objects.  These are part of OpenGL 3.0 and were supported
 * by the EXT_framebuffer_object extension prior to that.
 *)

structure FBO :> sig

    eqtype render_buffer
    eqtype frame_buffer

  (* generate render-buffer names *)
    val genRenderBuffer : unit -> render_buffer
    val genRenderBuffers : int -> render_buffer list
    val deleteRenderBuffers : render_buffer list -> unit

  (* generate frame-buffer names *)
    val genFrameBuffer : unit -> frame_buffer
    val genFrameBuffers : int -> frame_buffer list
    val deleteFrameBuffers : frame_buffer list -> unit

    eqtype status
    val COMPLETE : status
    val INCOMPLETE_ATTACHMENT : status
    val INCOMPLETE_MISSING_ATTACHMENT : status
    val INCOMPLETE_DUPLICATE_ATTACHMENT : status
    val INCOMPLETE_DIMENSIONS : status
    val INCOMPLETE_FORMATS : status
    val INCOMPLETE_DRAW_BUFFER : status
    val INCOMPLETE_READ_BUFFER : status
    val UNSUPPORTED : status

  (* check the status of the current frame-buffer object *)
    val checkStatus : unit -> status

    eqtype attachment
    val COLOR_ATTACHMENT0 : attachment
    val COLOR_ATTACHMENT1 : attachment
    val COLOR_ATTACHMENT2 : attachment
    val COLOR_ATTACHMENT3 : attachment
    val COLOR_ATTACHMENT4 : attachment
    val COLOR_ATTACHMENT5 : attachment
    val COLOR_ATTACHMENT6 : attachment
    val COLOR_ATTACHMENT7 : attachment
    val COLOR_ATTACHMENT8 : attachment
    val COLOR_ATTACHMENT9 : attachment
    val COLOR_ATTACHMENT10 : attachment
    val COLOR_ATTACHMENT11 : attachment
    val COLOR_ATTACHMENT12 : attachment
    val COLOR_ATTACHMENT13 : attachment
    val COLOR_ATTACHMENT14 : attachment
    val COLOR_ATTACHMENT15 : attachment
    val DEPTH_ATTACHMENT : attachment
    val STENCIL_ATTACHMENT : attachment
    val colorAttachment : int -> attachment

(*
    val texture1D : attachment * Texture.target1D * Texture.texture_id * int -> unit
    val texture2D : attachment * Texture.target2D * Texture.texture_id * int -> unit
    val texture3D : attachment * Texture.target3D * Texture.texture_id * int * int -> unit
*)

  end = struct

    open SML3dTypes
    open GLTypes
    open ExtFramebufferObject

    fun enum2int (i : glenum) = GLenum.toIntX i
    fun int2Enum i = GLenum.fromInt i

  (* render-buffer IDs *)
    structure RBId = ObjectIdFn (
      val name = "render buffer"
      type id = Word32.word
      fun toString id = Word32.fmt StringCvt.DEC id
      val hash = Word.fromLargeWord o Word32.toLargeWord
      structure A = struct
	  type array = GLuint.word array
	  val array = Array.array
	  val sub = Array.sub
	  val update = Array.update
	end
      val dummy = 0w0
      fun gen1 idRef = glGenRenderbufferEXT(1, idRef)
      val genn = glGenRenderbuffersEXT
      val delete = glDeleteRenderbuffersEXT)

    type render_buffer = RBId.object_id

    val genRenderBuffer = RBId.gen
    val genRenderBuffers = RBId.genList
    val deleteRenderBuffers = RBId.deleteList

  (* frame-buffer IDs *)
    structure FBId = ObjectIdFn (
      val name = "frame buffer"
      type id = Word32.word
      fun toString id = Word32.fmt StringCvt.DEC id
      val hash = Word.fromLargeWord o Word32.toLargeWord
      structure A = struct
	  type array = GLuint.word array
	  val array = Array.array
	  val sub = Array.sub
	  val update = Array.update
	end
      val dummy = 0w0
      fun gen1 idRef = glGenFramebufferEXT(1, idRef)
      val genn = glGenFramebuffersEXT
      val delete = glDeleteFramebuffersEXT)

    type frame_buffer = FBId.object_id

    val genFrameBuffer = FBId.gen
    val genFrameBuffers = FBId.genList
    val deleteFrameBuffers = FBId.deleteList

    type status = glenum
    val COMPLETE			= GL_FRAMEBUFFER_COMPLETE_EXT
    val INCOMPLETE_ATTACHMENT		= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
    val INCOMPLETE_MISSING_ATTACHMENT	= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
    val INCOMPLETE_DUPLICATE_ATTACHMENT	= GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT
    val INCOMPLETE_DIMENSIONS		= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
    val INCOMPLETE_FORMATS		= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
    val INCOMPLETE_DRAW_BUFFER		= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
    val INCOMPLETE_READ_BUFFER		= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
    val UNSUPPORTED			= GL_FRAMEBUFFER_UNSUPPORTED_EXT

(* NOTE: in OpenGL 3.1, one can pass DRAW_FRAMEBUFFER and READ_FRAMEBUFFER;
 * the latter is part of the EXST_framebuffer_blit extension
 *)
    fun checkStatus () = let
	  val sts = glCheckFramebufferStatusEXT GL_FRAMEBUFFER_EXT
	  in
	    if (sts = 0w0) then raise Fail "checkStatus error" else sts
	  end

    type attachment = glenum
    val COLOR_ATTACHMENT0	= GL_COLOR_ATTACHMENT0_EXT
    val COLOR_ATTACHMENT1	= GL_COLOR_ATTACHMENT1_EXT
    val COLOR_ATTACHMENT2	= GL_COLOR_ATTACHMENT2_EXT
    val COLOR_ATTACHMENT3	= GL_COLOR_ATTACHMENT3_EXT
    val COLOR_ATTACHMENT4	= GL_COLOR_ATTACHMENT4_EXT
    val COLOR_ATTACHMENT5	= GL_COLOR_ATTACHMENT5_EXT
    val COLOR_ATTACHMENT6	= GL_COLOR_ATTACHMENT6_EXT
    val COLOR_ATTACHMENT7	= GL_COLOR_ATTACHMENT7_EXT
    val COLOR_ATTACHMENT8	= GL_COLOR_ATTACHMENT8_EXT
    val COLOR_ATTACHMENT9	= GL_COLOR_ATTACHMENT9_EXT
    val COLOR_ATTACHMENT10	= GL_COLOR_ATTACHMENT10_EXT
    val COLOR_ATTACHMENT11	= GL_COLOR_ATTACHMENT11_EXT
    val COLOR_ATTACHMENT12	= GL_COLOR_ATTACHMENT12_EXT
    val COLOR_ATTACHMENT13	= GL_COLOR_ATTACHMENT13_EXT
    val COLOR_ATTACHMENT14	= GL_COLOR_ATTACHMENT14_EXT
    val COLOR_ATTACHMENT15	= GL_COLOR_ATTACHMENT15_EXT
    val DEPTH_ATTACHMENT	= GL_DEPTH_ATTACHMENT_EXT
    val STENCIL_ATTACHMENT	= GL_STENCIL_ATTACHMENT_EXT
    fun colorAttachment i = if (0 <= i) andalso (i <= 15)
	  then int2Enum i + COLOR_ATTACHMENT0
	  else raise Fail "bogus color attachment"

  end


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