orka_b455160b/orka/src/orka/interface/orka-ktx.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--  SPDX-License-Identifier: Apache-2.0
--
--  Copyright (c) 2017 onox <denkpadje@gmail.com>
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.

with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Streams;
with Ada.Strings.Hash;

with GL.Low_Level.Enums;
with GL.Objects.Textures;
with GL.Pixels;

with Orka.Resources;

private package Orka.KTX is
   pragma Preelaborate;

   package String_Maps is new Ada.Containers.Indefinite_Hashed_Maps
     (Key_Type        => String,
      Element_Type    => String,
      Hash            => Ada.Strings.Hash,
      Equivalent_Keys => "=");

   use GL.Low_Level.Enums;

   type Header (Compressed : Boolean) is record
      Kind   : GL.Low_Level.Enums.Texture_Kind;
      Width  : Size;
      Height : Size;
      Depth  : Size;
      Array_Elements : Size;
      Mipmap_Levels  : GL.Objects.Textures.Mipmap_Level;
      Bytes_Key_Value : Size;
      case Compressed is
         when True =>
            Compressed_Format : GL.Pixels.Compressed_Format;
         when False =>
            Data_Type       : GL.Pixels.Data_Type;
            Format          : GL.Pixels.Format;
            Internal_Format : GL.Pixels.Internal_Format;
      end case;
   end record
     with Dynamic_Predicate => Header.Width > 0
       and not (Header.Height = 0 and Header.Depth > 0)
       and (if Header.Compressed then Header.Mipmap_Levels > 0)
       and (case Header.Kind is
              when Texture_1D | Texture_2D | Texture_3D => Header.Array_Elements = 0,
              when Texture_Cube_Map | Texture_Rectangle => Header.Array_Elements = 0,
              when others                               => Header.Array_Elements > 0)
       and (case Header.Kind is
              when Texture_1D | Texture_1D_Array => Header.Height = 0,
              when Texture_2D | Texture_2D_Array => Header.Height > 0 and Header.Depth = 0,
              when Texture_Rectangle             => Header.Height > 0 and Header.Depth = 0,
              when Texture_3D                    => Header.Depth > 0,
              when Texture_Cube_Map       => Header.Width = Header.Height and Header.Depth = 0,
              when Texture_Cube_Map_Array => Header.Width = Header.Height and Header.Depth = 0,
              when others => raise Constraint_Error);

   subtype Bytes_Reference is Resources.Byte_Array_Pointers.Constant_Reference;

   function Valid_Identifier (Bytes : Bytes_Reference) return Boolean;

   function Get_Header (Bytes : Bytes_Reference) return Header;

   function Get_Key_Value_Map
     (Bytes  : Bytes_Reference;
      Length : Size) return String_Maps.Map;

   function Get_Length
     (Bytes  : Bytes_Reference;
      Offset : Ada.Streams.Stream_Element_Offset) return Natural;

   function Get_Data_Offset
     (Bytes  : Bytes_Reference;
      Bytes_Key_Value : Size) return Ada.Streams.Stream_Element_Offset;

   Invalid_Enum_Error : exception;

   function Create_KTX_Bytes
     (KTX_Header : Header;
      Get_Data   : not null access function (Level : GL.Objects.Textures.Mipmap_Level)
                                     return Resources.Byte_Array_Pointers.Pointer)
   return Resources.Byte_Array_Pointers.Pointer;

end Orka.KTX;