1. ------------------------------------------------------------------------- 
  2.  --  GL.Buffer.general - a generic for producing the various types of openGL vertex buffer objects. 
  3.  -- 
  4.  --  Copyright (c) Rod Kay 2007 
  5.  --  AUSTRALIA 
  6.  --  Permission granted to use this software, without any warranty, 
  7.  --  for any purpose, provided this copyright note remains attached 
  8.  --  and unmodified if sources are distributed further. 
  9.  ------------------------------------------------------------------------- 
  10.  
  11. with Interfaces.C.Pointers; 
  12.  
  13. generic 
  14.    type base_Object is new GL.Buffer.Object with private; 
  15.  
  16.    type Index         is mod <>; 
  17.    type Element       is private; 
  18.    type Element_Array is array (Index range <>) of aliased Element; 
  19.  
  20. package GL.Buffer.general is 
  21.  
  22.    pragma Elaborate_Body; 
  23.  
  24.    type General_Object is new base_Object with private; 
  25.  
  26.    function  To_Buffer (From : access Element_Array; Usage  : VBO_Usage) return General_Object; 
  27.  
  28.    procedure Set (Self         : in out General_Object; 
  29.                   Set_Position :        Positive := 1;    -- tbd : make this raise 'constraint_Error' instead of openGL_Error, when bounds are violated. 
  30.                   To           :        Element_Array); 
  31.    function  Get (Self : access General_Object) return Element_Array; 
  32.  
  33.    -- buffer memory map 
  34.    -- 
  35.  
  36.    type memory_Map is abstract tagged private; 
  37.  
  38.    procedure Release (Self : memory_Map); 
  39.    -- 
  40.    -- 'release' must be called to release the buffers data back to the GL server. 
  41.    -- 
  42.    -- May raise Corrupt_Buffer if the Buffer has become corrupt since the data 
  43.    -- was initially mapped. This can occur for system - specific reasons that affect the availability of graphics memory, 
  44.    -- such as screen mode changes. In such situations, the data store contents are undefined, and an application 
  45.    -- reinitialize the data store. 
  46.    -- 
  47.    Corrupt_Buffer  : exception; 
  48.  
  49.    type read_only_Map  is new memory_Map with private; 
  50.  
  51.    function  Map (Self  : access General_Object) return read_only_Map'Class; 
  52.  
  53.    function  Get (Self : read_only_Map; Get_Position : Index) return Element; 
  54.    function  Get (Self : read_only_Map; Get_Position : Index; Count : Positive) return Element_Array; 
  55.  
  56.    type write_only_Map is new memory_Map with private; 
  57.  
  58.    function  Map (Self : access General_Object) return write_only_Map'Class; 
  59.  
  60.    procedure Set (Self : write_only_Map; Set_Position : Index; To : access Element); 
  61.    procedure Set (Self : write_only_Map; Set_Position : Index; To :        Element); 
  62.  
  63.    type read_write_Map is new memory_Map with private; 
  64.  
  65.    function  Map (Self  : access General_Object) return read_write_Map'Class; 
  66.  
  67.    function  Get (Self : read_write_Map; Get_Position : Index) return Element; 
  68.    function  Get (Self : read_write_Map; Get_Position : Index; Count : Positive) return Element_Array; 
  69.  
  70.    procedure Set (Self : read_write_Map; Set_Position : Index; To : access Element); 
  71.    procedure Set (Self : read_write_Map; Set_Position : Index; To :        Element); 
  72.  
  73. private 
  74.  
  75.    type General_Object is new base_Object with null record; 
  76.  
  77.    default_Terminator : Element;     -- no 'i.c.Pointers' subprogram is called which uses this, so a default 'Element' should suffice. 
  78.  
  79.    pragma Warnings (Off, """default_Terminator"" may be referenced before it has a value"); 
  80.    package Element_Pointers is new interfaces.C.Pointers (Index, Element, Element_Array, default_Terminator); 
  81.    pragma Warnings (On,  """default_Terminator"" may be referenced before it has a value"); 
  82.  
  83.    type memory_Map is abstract tagged 
  84.       record 
  85.          vbo_Target  : GL.VBO_Target; 
  86.  
  87.          Data  : Element_Pointers.Pointer; 
  88.          Last  : Index; 
  89.       end record; 
  90.  
  91.    type read_only_Map  is new memory_Map with null record; 
  92.    type write_only_Map is new memory_Map with null record; 
  93.    type read_write_Map is new memory_Map with null record; 
  94.  
  95. end GL.Buffer.general;