Hi,

these are some small additions I use that I figured might be useful to someone 
else as well.

Attached is a patch to add support for compressed textures and 
draw-pixels/read-pixels. I'm not sure of how well these last two play with 
various pixelstore modes but it does everything I need it to do (eg. take 
screenshots, peek at the depth-buffer etc).

Sincerely yours,
Mikael Lax

PS: Patch is against cl-opengl-thomas branch.
{
hunk ./gl/framebuffer.lisp 146
-(defun read-pixels (x y width height)
-  (declare (ignore x y width height))
-  (error "not implemented"))
+(defun read-pixels (x y width height format type)
+  (let* ((mult (ecase format
+                 ((:red :green :blue :alpha :luminance) 1)
+                 ((:depth-component :color-index :stencil-index) 1)
+                 (:luminance-alpha 2)
+                 ((:rgb :bgr) 3)
+                 ((:rgba :bgra) 4)))
+         (size (* width height mult))
+         (result-data (make-sequence 'vector size))
+         (real-type (symbolic-type->real-type type)))
+    (with-foreign-object (array real-type size)
+      (%gl:read-pixels x y width height format type array)
+      (dotimes (i size result-data)
+        (setf (svref result-data i)
+              (mem-aref array real-type i))))))
hunk ./gl/package.lisp 153
+   ;; 3.6.4 Pixel Rasterization
+   #:draw-pixels
hunk ./gl/package.lisp 168
+   ;; 3.8.3 Compressed Texture Images
+   #:compressed-tex-image-1d
+   #:compressed-tex-image-2d
+   #:compressed-tex-image-3d
+   #:compressed-tex-sub-image-1d
+   #:compressed-tex-sub-image-2d
+   #:compressed-tex-sub-image-3d
hunk ./gl/rasterization.lisp 84
+;;; 3.6.1 Pixel Storage Modes
+
hunk ./gl/rasterization.lisp 94
+;;; 3.6.3 Pixel Transfer Modes
+
hunk ./gl/rasterization.lisp 112
+;;; 3.6.4 Rasterization of Pixel Rectangles
+
+(defun draw-pixels (width height format type data)
+  (with-pixel-array (array type data)
+    (%gl:draw-pixels width height format type array)))
+
hunk ./gl/rasterization.lisp 201
-;;; TODO
+(defun compressed-tex-image-1d (target level internal-format width border
+                                data &optional (image-size (length data)))
+  (if (pointerp data)
+      (%gl:compressed-tex-image-1d target level internal-format
+                                   width border image-size data)
+      (with-pixel-array (array :unsigned-byte data)
+        (%gl:compressed-tex-image-1d target level internal-format
+                                     width border image-size array))))
+
+(defun compressed-tex-image-2d (target level internal-format width height border
+                                data &optional (image-size (length data)))
+  (if (pointerp data)
+      (%gl:compressed-tex-image-2d target level internal-format
+                                   width height border image-size data)
+      (with-pixel-array (array :unsigned-byte data)
+        (%gl:compressed-tex-image-2d target level internal-format
+                                     width height border image-size array))))
+
+(defun compressed-tex-image-3d (target level internal-format width height depth
+                                border data &optional (image-size (length data)))
+  (if (pointerp data)
+      (%gl:compressed-tex-image-3d target level internal-format width
+                                   height depth border image-size data)
+      (with-pixel-array (array :unsigned-byte data)
+        (%gl:compressed-tex-image-3d target level internal-format width
+                                     height depth border image-size array))))
+
+(defun compressed-tex-sub-image-1d (target level xoffset width format
+                                    data &optional (image-size (length data)))
+  (if (pointerp data)
+      (%gl:compressed-tex-sub-image-1d target level xoffset width
+                                       format image-size data)
+      (with-pixel-array (array :unsigned-byte data)
+        (%gl:compressed-tex-sub-image-1d target level xoffset width
+                                         format image-size array))))
+
+(defun compressed-tex-sub-image-2d (target level xoffset yoffset width height
+                                    format data &optional (image-size (length data)))
+  (if (pointerp data)
+      (%gl:compressed-tex-sub-image-2d target level xoffset yoffset width height
+                                       format image-size data)
+      (with-pixel-array (array :unsigned-byte data)
+        (%gl:compressed-tex-sub-image-2d target level xoffset yoffset width height
+                                         format image-size array))))
+
+(defun compressed-tex-sub-image-3d (target level xoffset yoffset zoffset width height
+                                    depth format data &optional (image-size (length data)))
+  (if (pointerp data)
+      (%gl:compressed-tex-sub-image-3d target level xoffset yoffset zoffset width
+                                       height depth format image-size data)
+      (with-pixel-array (array :unsigned-byte data)
+        (%gl:compressed-tex-sub-image-3d target level xoffset yoffset zoffset width
+                                         height depth format image-size array))))
}
_______________________________________________
cl-opengl-devel mailing list
cl-opengl-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cl-opengl-devel

Reply via email to