On Fri, 04 May 2007 20:47:49 +0100
Luis Oliveira <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> Mikael Lax <[EMAIL PROTECTED]> writes:
> > Attached is a patch to add support for compressed textures and
> > draw-pixels/read-pixels.
> 
> Thanks.  Darcs doesn't like your patch though, probably because you
> removed the context information.

Hello,

my apologies for the incomplete patch, I haven't used darcs before. Attached 
now is a second attempt, if it still doesn't work I would appreciate any advice 
on how darcs patches are actually made.

Sincerely yours,
Mikael Lax
{
hunk ./gl/framebuffer.lisp 146
 
 ;;; 4.3.2 Reading Pixels
 
-(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))))))
 
 (import-export %gl:read-buffer)
 
hunk ./gl/package.lisp 153
    ;; 3.5.4 Options Controlling Polygon Rasterization
    #:polygon-mode
    #:polygon-offset
+   ;; 3.6.4 Pixel Rasterization
+   #:draw-pixels
    ;; 3.8.1 Texture Image Specification
    #:tex-image-1d
    #:tex-image-2d
hunk ./gl/package.lisp 168
    #:copy-tex-sub-image-1d
    #:copy-tex-sub-image-2d
    #:copy-tex-sub-image-3d
+   ;; 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
    ;; 3.8.4 Texture Parameters
    #:tex-parameter
    ;; 3.8.12 Texture Objects
hunk ./gl/rasterization.lisp 84
 ;;; 3.6 Pixel Rectangles
 ;;;
 
+;;; 3.6.1 Pixel Storage Modes
+
 (defun pixel-store (pname value)
   (ecase pname
     ((:unpack-swap-bytes :unpack-lsb-first)
hunk ./gl/rasterization.lisp 94
       :unpack-alignment :unpack-image-height :unpack-skip-images)
      (%gl:pixel-store-i pname value))))
 
+;;; 3.6.3 Pixel Transfer Modes
+
 (defun pixel-transfer (pname value)
   (case pname
     ((:map-color :map-stencil)
hunk ./gl/rasterization.lisp 112
         (setf (mem-aref p '%gl:float i) (float (elt values i))))
       (%gl:pixel-map-fv map n p))))
 
+;;; 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)))
+
 ;;;
 ;;; 3.8 Texturing
 ;;;
hunk ./gl/rasterization.lisp 201
 
 ;;; 3.8.3 Compressed Texture Images
 
-;;; 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))))
 
 ;;; 3.8.4 Texture parameters
 
}
_______________________________________________
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