Skip to content

Drawing huge polygons #160

@Gleefre

Description

@Gleefre

Trying to draw a huge polygon (~150 vertices randomly generated):

(defpackage #:sketch-user
  (:use #:cl)
  (:local-nicknames (#:s #:sketch)))

(in-package #:sketch-user)

(s:defsketch huge-polygon ()
  (apply #'s:polygon (loop repeat 300 collect (random 400))))

(make-instance 'huge-polygon)

results in an OpenGL error "OpenGL signalled (1281 . INVALID-VALUE) from MAP-BUFFER-RANGE.":
image

The problem is that a huge polygon contains too many triangles in its triangulation (~10-15k of them):

(sketch::with-environment (sketch::make-env)
  (sketch::with-pen (sketch::make-default-pen)
    ;; we fake an environment because triangulate needs a winding rule from a pen
    (length
     (sketch::triangulate
      (loop repeat 300 collect (random 400))))))
; => 10995
; OR=> 15717
; ...

The drawing buffer size is 2^17 = ~130k bytes by default; each vertex takes 20 bytes, which leaves place for ~6.5k vertices in a single shape, which is lower than a ~30-45k vertices in a huge polygon.

While increasing the drawing buffer size (sketch::*buffer-size*) is good enough workaround, draw-shape/push-vertices should be able to handle case when the drawing buffer is too small.

Possible solutions include increasing the buffer size or splitting one drawing call into several calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions