1 module dcl.platform;
2 
3 import dcl.base;
4 
5 import dcl.device;
6 import dcl.context;
7 
8 ///
9 class CLPlatform : CLObject
10 {
11 private:
12 
13     static CLPlatform[cl_platform_id] used;
14 
15     this( cl_platform_id id )
16     {
17         enforce( id !is null, new CLException( "can't create platform with null id" ) );
18         enforce( id !in used, new CLException( "can't create existing platform" ) );
19         this.id = id;
20         used[id] = this;
21 
22         updateDevs();
23     }
24 
25     void updateDevs()
26     {
27         uint nums;
28         auto type = CLDevice.Type.ALL;
29 
30         checkCall!clGetDeviceIDs( id, type, 0, null, &nums );
31         auto ids = new cl_device_id[](nums);
32         checkCall!clGetDeviceIDs( id, type, nums, ids.ptr, null );
33 
34         _devices = regChild( ids.map!(a=>CLDevice.getFromID(a)).array );
35     }
36 
37     CLDevice[] _devices;
38 
39 package:
40     ///
41     cl_platform_id id;
42 
43 public:
44 
45     static CLPlatform getFromID( cl_platform_id id )
46     {
47         if( id is null ) return null;
48         if( id in used ) return used[id];
49         return new CLPlatform( id );
50     }
51 
52     ///
53     CLDevice[] devices() @property { return _devices; }
54 
55     ///
56     static CLPlatform[] getAll()
57     {
58         uint nums;
59         checkCall!clGetPlatformIDs( 0, null, &nums );
60         auto ids = new cl_platform_id[](nums);
61         checkCall!clGetPlatformIDs( nums, ids.ptr, null );
62 
63         return ids.map!(a=>getFromID(a)).array;
64     }
65 
66     static private enum info_list =
67     [
68         "string name",
69         "string vendor",
70         "string profile",
71         "string version:_version",
72         "string extensions"
73     ];
74 
75     mixin( infoMixin( "platform", info_list ) );
76 
77 protected:
78 
79     override void selfDestroy() { used.remove(id); }
80 }