flyx / OpenGLAda

Thick Ada binding for OpenGL and GLFW
flyx.github.io/OpenGLAda/
MIT License
96 stars 13 forks source link

Address of Array_Buffer #118

Closed rogermc2 closed 6 years ago

rogermc2 commented 6 years ago

For debugging purposes, I've been trying to get the address of the target Array_Buffer without success using:

  type Image_Data is array (UInt range <>) of aliased Single;
   package Image_Data_Pointers is new
     Interfaces.C.Pointers (UInt, Single, Image_Data, Single'Last);
   function Read_Image_Data is new
     GL.Objects.Buffers.Pointer (Image_Data_Pointers);

...

      Raw_Data    : Image_Data (1 .. Total_Data_Size);
      Raw_Ptr     : Image_Data_Pointers.Pointer;
      Raw_Copy    : Single;

...

     Image_Data'Read (Data_Stream, Raw_Data);
     Vertex_Buffer.Initialize_Id;
      Array_Buffer.Bind (Vertex_Buffer);
      Utilities.Load_Vertex_Buffer (Array_Buffer,  Vertex_Data.Vertex_Buffer_Data, Static_Draw);
      Raw_Ptr := Read_Image_Data (Array_Buffer);
      if Raw_Ptr /= null then
         Raw_Copy := Raw_Ptr.all;
         Put_Line ("Raw_Copy: " & Single'Image (Raw_Copy));
      else
         Put_Line ("Array_Buffer pointer is null.");
      end if;

I've tried this in an example that produces '"Array_Buffer pointer is null."' but otherwise works displaying the expected image, so the Array_Buffer is definitely being initialised, bound and loaded. Sorry to bother you, but I'm really stuck with my current project which needs to load byte data:

   type Image_Data is array (UInt range <>) of aliased UByte;
   package Image_Data_Pointers is new
     Interfaces.C.Pointers (UInt, UByte, Image_Data, UByte'Last);
   procedure Load_Image_Data is new
     GL.Objects.Buffers.Load_To_Buffer (Image_Data_Pointers);

...

         Raw_Data    : Image_Data (1 .. Total_Data_Size);

...

         Load_Image_Data (Array_Buffer, Raw_Data, Static_Draw);

Or is there some other way of checking that the Array_Buffer target is being loaded? Everything else I've checked seems OK.

rogermc2 commented 6 years ago

Awaiting further changes and investigation

flyx commented 6 years ago

I think you need to map the buffer first using GL.Objects.Buffers.Map. Otherwise, the buffer is not in the client‘s address space; that‘s at least how I understand the documentation.

rogermc2 commented 6 years ago

Thanks, I'll try that.