1:- module(ptr, [ptr_store_float32s/3,
    2                ptr_store_uint16s/3,
    3                ptr_store_uint32s/3
    4                ]).    5
    6:- use_foreign_library(foreign(ptr)).    7
    8% PtrBlob is defined entirely in C++ (ptr.h, included by sdl.cpp, cairo.cpp,
    9% and ptr.cpp).  This module provides the type-check hook, rich error message
   10% for the `ptr_blob` type, and bulk typed writers for filling mapped memory
   11% regions (e.g. GPU transfer buffers) with vertex/index data from Prolog
   12% lists.
   13%
   14% The blob type itself is registered at runtime by whichever foreign module
   15% loads first (via the ptr_blob_type() first-loader-wins mechanism in
   16% ptr.h); no ptr.so exists for the blob type alone — ptr.so only provides
   17% the writer predicates.
   18
   19:- multifile error:has_type/2.   20error:has_type(ptr_blob, X) :- blob(X, ptr_blob).
   21
   22:- multifile prolog:error_message//1.   23prolog:error_message(type_error(ptr_blob, Culprit)) -->
   24   [ 'ptr_blob (a non-owning pointer view blob), found ~q'-[Culprit] ].
   25
   26% --- typed writers ----------------------------------------------------------
   27% These predicates write Prolog lists into a PtrBlob's memory region at the
   28% given byte offset.  They are used to fill GPU transfer buffers (mapped via
   29% sdl_mapgputransferbuffer/3) with vertex or index data before uploading to
   30% GPU buffers.  One Prolog→C crossing per call (bulk, not per-element).
   31
   32ptr_store_float32s(Ptr, Offset, List) :-
   33   must_be(ptr_blob, Ptr),
   34   must_be(nonneg, Offset),
   35   must_be(list(number), List),
   36   ptr_store_float32s_(Ptr, Offset, List).
   37
   38ptr_store_uint16s(Ptr, Offset, List) :-
   39   must_be(ptr_blob, Ptr),
   40   must_be(nonneg, Offset),
   41   must_be(list(integer), List),
   42   ptr_store_uint16s_(Ptr, Offset, List).
   43
   44ptr_store_uint32s(Ptr, Offset, List) :-
   45   must_be(ptr_blob, Ptr),
   46   must_be(nonneg, Offset),
   47   must_be(list(integer), List),
   48   ptr_store_uint32s_(Ptr, Offset, List)