text
stringlengths
0
234
ID : Integer; -- ID is the texture identifier to bind to
blending_hint : out Boolean) is -- has blending / transparency /alpha ?
begin
case format is
when BMP => Load_BMP (s, ID, blending_hint);
when TGA => Load_TGA (s, ID, blending_hint);
end case;
end Load;
-------------
-- Outputs --
-------------
generic
type Number is mod <>;
s : Stream_Access;
procedure Write_Intel_x86_number (n : Number);
procedure Write_Intel_x86_number (n : Number) is
m : Number := n;
bytes : constant Integer := Number'Size / 8;
begin
for i in 1 .. bytes loop
U8'Write (s, U8 (m mod 256));
m := m / 256;
end loop;
end Write_Intel_x86_number;
procedure Write_raw_BGR_frame (s : Stream_Access; width, height : Natural) is
-- 4 - byte padding for .bmp/.avi formats is the same as GL's default
-- padding : see glPixelStore, GL_[UN]PACK_ALIGNMENT = 4 as initial value.
-- http://www.opengl.org/sdk/docs/man/xhtml/glPixelStore.xml
--
padded_row_size : constant Positive :=
4 * Integer (C_Float'Ceiling (C_Float (width) * 3.0 / 4.0));
-- (in bytes)
--
type Temp_bitmap_type is array (Natural range <>) of aliased GL.Ubyte;
PicData : Temp_bitmap_type (0 .. (padded_row_size + 4) * (height + 4) - 1);
-- No dynamic allocation needed!
-- The "+ 4" are there to avoid parity address problems when GL writes
-- to the buffer.
type loc_pointer is new GL.pointer;
function Cvt is new Ada.Unchecked_Conversion (System.Address, loc_pointer);
-- This method is functionally identical as GNAT's Unrestricted_Access
-- but has no type safety (cf GNAT Docs)
pragma No_Strict_Aliasing (loc_pointer); -- recommended by GNAT 2005 +
pPicData : loc_pointer;
data_max : constant Integer := padded_row_size * height - 1;
begin
pPicData := Cvt (PicData (0)'Address);
GL.ReadPixels (
0, 0,
GL.Sizei (width), GL.Sizei (height),
GL.BGR,
GL.GL_UNSIGNED_BYTE,
GL.pointer (pPicData)
);
if workaround_possible then
declare
use Ada.Streams;
SE_Buffer : Stream_Element_Array (0 .. Stream_Element_Offset (PicData'Last));
for SE_Buffer'Address use PicData'Address;
pragma Import (Ada, SE_Buffer);
begin
Ada.Streams.Write (s.all, SE_Buffer (0 .. Stream_Element_Offset (data_max)));
Function Definition: function Cvt is new Ada.Unchecked_Conversion (System.Address, GL_IntPointer);
Function Body: -- This method is functionally identical as GNAT's Unrestricted_Access
-- but has no type safety (cf GNAT Docs)
pragma No_Strict_Aliasing (GL_IntPointer); -- recommended by GNAT 2005+
begin
-- Größe des Viewports abfragen --> Spätere Bildgrößenangaben
GL.GetIntegerv (GL.VIEWPORT, GL.intPointer (Cvt (Screenshot_Viewport (0)'Address)));
-- Initialisieren der Daten des Headers
FileHeader.bfType := 16#4D42#; -- 'BM'
FileHeader.bfOffBits := Bitmap_Info_Header'Size / 8 + Bitmap_File_Header'Size / 8;
-- Schreiben der Bitmap - Informationen
FileInfo.biSize := Bitmap_Info_Header'Size / 8;
FileInfo.biWidth := I32 (Screenshot_Viewport (2));
FileInfo.biHeight := I32 (Screenshot_Viewport (3));
FileInfo.biPlanes := 1;
FileInfo.biBitCount := 24;
FileInfo.biCompression := 0;
FileInfo.biSizeImage :=
U32 (
-- 4 - byte padding for .bmp/.avi formats
4 * Integer (C_Float'Ceiling (C_Float (FileInfo.biWidth) * 3.0 / 4.0)) *
Integer (FileInfo.biHeight)
);
-- Größenangabe auch in den Header übernehmen
FileHeader.bfSize := FileHeader.bfOffBits + FileInfo.biSizeImage;
-- Und den ganzen Müll in die Datei schieben ; - )
-- Moderne Leute nehmen dafür auch Streams . ..