Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing huge polygons #160

Open
Gleefre opened this issue Feb 10, 2024 · 2 comments
Open

Drawing huge polygons #160

Gleefre opened this issue Feb 10, 2024 · 2 comments

Comments

@Gleefre
Copy link
Contributor

Gleefre commented Feb 10, 2024

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.

@Kevinpgalligan
Copy link
Contributor

The problem I see with batching the vertices is that there could be discontinuities in the texture. It's better than crashing, anyway. And we can increase the drawing buffer size (and maybe make it configurable) to avoid the discontinuities as much as possible.

@Kevinpgalligan
Copy link
Contributor

Kevinpgalligan added a commit to Kevinpgalligan/sketch that referenced this issue Oct 23, 2024
Fix for this bug: vydd#160

The draw buffer isn't large enough for shapes that consist of
more than about 6000 vertices, so we need to batch the draw
calls. Different batching behaviour is required for different
primitive types, e.g. for triangle strips, in each batch you
have to include the last 2 vertices from the previous batch so
that the strip is continuous. I've only covered the :triangles
and :triangle-strip primitive types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants