1. ------------------------------------------------------------------------- 
  2.  --  GL.Geometry - GL vertex buffer Object 
  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 GL.Errors; 
  12.  
  13. --  with Ada.Numerics.Generic_Elementary_functions; 
  14. --  with Ada.Text_IO; use Ada.Text_IO; 
  15.  
  16. --  with System; 
  17.  
  18. package body GL.Buffer is 
  19.  
  20.    -- 'Name' support 
  21.    -- 
  22.  
  23.    function new_vbo_Name return vbo_Name is 
  24.  
  25.       the_Name : aliased vbo_Name; 
  26.  
  27.    begin 
  28.       GL.Gen_Buffers (1,  the_Name'Unchecked_Access); 
  29.       return the_Name; 
  30.    end new_vbo_Name; 
  31.  
  32.    procedure Free (the_vbo_Name : vbo_Name) is 
  33.  
  34.       the_Name  : aliased vbo_Name := the_vbo_Name; 
  35.  
  36.    begin 
  37.       GL.Delete_Buffers (1, the_Name'Unchecked_Access); 
  38.    end Free; 
  39.  
  40.    pragma Unreferenced (Free); 
  41.  
  42.    -- object 
  43.    -- 
  44.  
  45.    procedure Verify_Name (Self : in out Object'Class) is 
  46.  
  47.    begin 
  48.       if Self.Name = 0 then 
  49.          Self.Name := new_vbo_Name; 
  50.       end if; 
  51.    end Verify_Name; 
  52.  
  53.    procedure Enable (Self : Object'Class) is 
  54.  
  55.    begin 
  56.       pragma Assert (Self.Name > 0); 
  57.  
  58.       GL.BindBuffer (Extract_VBO_Target (Self),  Self.Name); 
  59.    end Enable; 
  60.  
  61.    procedure Destroy (Self : in out Object'Class) is 
  62.  
  63.    begin 
  64.       GL.BindBuffer    (Extract_VBO_Target (Self), 0); 
  65.       GL.Delete_Buffers (1, Self.Name'Unchecked_Access); 
  66.    end Destroy; 
  67.  
  68.    -- array object 
  69.    -- 
  70.  
  71.    overriding function Extract_VBO_Target (Self : array_Object) return GL.VBO_Target is (GL.ARRAY_BUFFER); 
  72.  
  73.    -- element array object 
  74.    -- 
  75.  
  76.    overriding function Extract_VBO_Target (Self : element_array_Object) return GL.VBO_Target is (GL.ELEMENT_ARRAY_BUFFER); 
  77.  
  78.  --     -- texture coordinates 
  79.  --     -- 
  80.  -- 
  81.  --     procedure set_texture_Coordinates (Self  : in out vertex_buffer_Object;   To  : access GL.textures.Coordinate_2D_array) 
  82.  --     is 
  83.  --        use type GL.SizeIPtr; 
  84.  --     begin 
  85.  --        verify_Name (Self); 
  86.  -- 
  87.  --        GL.bindBuffer (gl.ARRAY_BUFFER,  self.Name); 
  88.  --        GL.bufferData (gl.ARRAY_BUFFER,  To.all'size / 8, 
  89.  --                                         to_Pointer (To (To'First).S'Access), 
  90.  --                                         GL.STATIC_DRAW);                        -- tbd : make this a parameter. 
  91.  --     end; 
  92.  
  93. end GL.Buffer;