add high-level gl bindings for fragment and framebuffer operations
authorDaniel Hartwig <mandyke@gmail.com>
Mon, 11 Feb 2013 04:19:04 +0000 (12:19 +0800)
committerDaniel Hartwig <mandyke@gmail.com>
Mon, 11 Feb 2013 04:19:04 +0000 (12:19 +0800)
* figl/gl.scm (gl-clear, set-gl-clear-color, etc.): High-level
  bindings for functions pertaining to fragment and framebuffer
  operations.  There is now enough high-level to run the fixed
  function pipeline.

* examples/glut/demo.scm: Use high-level gl bindings.

examples/glut/demo.scm
figl/gl.scm

index 1e62e8a..6038f90 100644 (file)
@@ -1,21 +1,17 @@
 #!/usr/bin/env guile
 !#
 
 #!/usr/bin/env guile
 !#
 
-(use-modules (figl glut enums)
-             (figl glut low-level)
+(use-modules (figl glut low-level)
              (figl glut)
              (figl glut)
-             (figl gl enums)
-             (figl gl low-level)
+             (figl gl)
              (system foreign))
 
 (define (render-scene)
              (system foreign))
 
 (define (render-scene)
-  (glClear (clear-buffer-mask color-buffer depth-buffer))
-  (glBegin (begin-mode triangles))
-  (glVertex3f -0.5 -0.5 0.0)
-  (glVertex3f 0.5 0.0 0.0)
-  (glVertex3f 0.0 0.5 0.0)
-  (glEnd)
-
+  (gl-clear (clear-buffer-mask color-buffer depth-buffer))
+  (gl-begin (begin-mode triangles)
+    (gl-vertex -0.5 -0.5 0.0)
+    (gl-vertex 0.5 0.0 0.0)
+    (gl-vertex 0.0 0.5 0.0))
   (glutSwapBuffers))
 
 (glutInitWindowSize 320 200)
   (glutSwapBuffers))
 
 (glutInitWindowSize 320 200)
index 1dd853e..8fbb0b5 100644 (file)
 
 (define-module (figl gl)
   #:use-module (figl runtime)
 
 (define-module (figl gl)
   #:use-module (figl runtime)
+  #:use-module (figl gl types)
   #:use-module (figl gl enums)
   #:use-module (figl gl enums)
-  #:use-module ((figl gl low-level) #:renamer (symbol-prefix-proc '%)))
+  #:use-module ((figl gl low-level) #:renamer (symbol-prefix-proc '%))
+  #:use-module (system foreign))
 
 ;; Notice there is no #:export clause.  Exports are done inline to
 ;; facilitate re-exporting low-level bindings (and changing that
 
 ;; Notice there is no #:export clause.  Exports are done inline to
 ;; facilitate re-exporting low-level bindings (and changing that
 (define* (gl-vertex x y #:optional (z 0.0) (w 1.0))
   (%glVertex4f x y z w))
 
 (define* (gl-vertex x y #:optional (z 0.0) (w 1.0))
   (%glVertex4f x y z w))
 
-(define* (gl-tex-coord s #:optional (t 0.0) (r 0.0) (q 1.0))
+(define* (gl-texture-coordinate s #:optional (t 0.0) (r 0.0) (q 1.0))
   (%glTexCoord4f s t r q))
 
   (%glTexCoord4f s t r q))
 
-(define* (gl-multi-tex-coord texture s #:optional (t 0.0) (r 0.0) (q 1.0))
+(define* (gl-multi-texture-coordinate texture s #:optional (t 0.0) (r 0.0) (q 1.0))
   (%glMultiTexCoord4f texture s t r q))
 
 (define* (gl-color red green blue #:optional (alpha 1.0))
   (%glColor4f red green blue alpha))
 
   (%glMultiTexCoord4f texture s t r q))
 
 (define* (gl-color red green blue #:optional (alpha 1.0))
   (%glColor4f red green blue alpha))
 
-(define* (gl-vertex-attrib index x #:optional (y 0.0) (z 0.0) (w 1.0))
+(define* (gl-vertex-attribute index x #:optional (y 0.0) (z 0.0) (w 1.0))
   (%glVertexAttrib4f index x y z w))
 
 (export gl-vertex
   (%glVertexAttrib4f index x y z w))
 
 (export gl-vertex
-        gl-tex-coord
-        gl-multi-tex-coord
-        gl-color)
+        gl-texture-coordinate
+        gl-multi-texture-coordinate
+        gl-color
+        gl-vertex-attribute)
 
 (re-export (%glNormal3f . gl-normal)
 
 (re-export (%glNormal3f . gl-normal)
-           (%glFogCoordf . gl-fog-coord)
+           (%glFogCoordf . gl-fog-coordinate)
            (%glSecondaryColor3f . gl-secondary-color)
            (%glIndexi . gl-index))
 
            (%glSecondaryColor3f . gl-secondary-color)
            (%glIndexi . gl-index))
 
 
 (re-export (%glEnable . gl-enable)
            (%glDisable . gl-disable))
 
 (re-export (%glEnable . gl-enable)
            (%glDisable . gl-disable))
+
+\f
+;;;
+;;; 4.1 Per-Fragment Operations
+;;;
+
+(define* (set-gl-stencil-function stencil-function k #:key
+                                  (mask #xFFFFFFFF) ; 32-bit mask
+                                  face)
+  (if face
+      (%glStencilFuncSeparate face stencil-function k mask)
+      (%glStencilFunc stencil-function k mask)))
+
+(define* (set-gl-stencil-operation stencil-fail depth-fail depth-pass #:key
+                                   face)
+  (if face
+      (%glStencilOpSeparate face stencil-fail depth-fail depth-pass)
+      (%glStencilOp stencil-fail depth-fail depth-pass)))
+
+;; TODO: 4.1.7 Occlusion Queries
+
+(define* (set-gl-blend-equation mode-rgb #:optional (mode-alpha mode-rgb))
+  (%glBlendEquationSeparate mode-rgb mode-alpha))
+
+(define* (set-gl-blend-function src-rgb dest-rgb #:optional
+                                (src-alpha src-rgb)
+                                (dest-alpha dest-rgb))
+  (%glBlendFuncSeparate src-rgb dest-rgb src-alpha dest-alpha))
+
+(export set-gl-stencil-function
+        set-gl-stencil-operation
+        set-gl-blend-equation
+        set-gl-blend-function
+        )
+
+(re-export (%glScissor . set-gl-scissor)
+           (%glSampleCoverage . set-gl-sample-coverage)
+           (%glAlphaFunc . set-gl-alpha-function)
+           (%glDepthFunc . set-gl-depth-function)
+           (%glBlendColor . set-gl-blend-color)
+           (%glLogicOp . set-gl-logic-operation)
+           )
+
+;;;
+;;; 4.2 Whole Framebuffer Operations
+;;;
+
+(define (set-gl-draw-buffers buffers)
+  (let* ((n (length buffers))
+         (buffers (make-c-struct (make-list n (GLenum))
+                                 buffers)))
+    (%glDrawBuffers n buffers)))
+
+(define* (set-gl-stencil-mask mask #:key face)
+  (if face
+      (%glStencilMaskSeparate face mask)
+      (%glStencilMask mask)))
+
+(export set-gl-draw-buffers
+        set-gl-stencil-mask)
+
+(re-export (%glDrawBuffer . set-gl-draw-buffer)
+           (%glIndexMask . set-gl-index-mask)
+           (%glColorMask . set-gl-color-mask)
+           (%glDepthMask . set-gl-depth-mask)
+           (%glClear . gl-clear)
+           (%glClearColor . set-gl-clear-color)
+           (%glClearIndex . set-gl-clear-index)
+           (%glClearDepth . set-gl-clear-depth)
+           (%glClearStencil . set-gl-clear-stencil-value)
+           (%glClearAccum . set-gl-clear-accumulation-color)
+           (%glAccum . set-gl-accumulation-buffer-operation))
+
+;;;
+;;; 4.3 Drawing, Reading, and Copying Pixels
+;;;
+
+;; TODO: read-pixels
+
+(re-export (%glReadBuffer . set-gl-read-buffer)
+           (%glCopyPixels . gl-copy-pixels))