mtl.h (6749B)
1 // Copyright 2018 The Ebiten Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build darwin 16 17 #include <stddef.h> 18 #include <stdint.h> 19 20 typedef unsigned long uint_t; 21 22 struct Device { 23 void *Device; 24 uint8_t Headless; 25 uint8_t LowPower; 26 uint8_t Removable; 27 uint64_t RegistryID; 28 const char *Name; 29 }; 30 31 struct Devices { 32 struct Device *Devices; 33 int Length; 34 }; 35 36 struct Library { 37 void *Library; 38 const char *Error; 39 }; 40 41 struct RenderPipelineDescriptor { 42 void *VertexFunction; 43 void *FragmentFunction; 44 uint16_t ColorAttachment0PixelFormat; 45 uint8_t ColorAttachment0BlendingEnabled; 46 uint8_t ColorAttachment0DestinationAlphaBlendFactor; 47 uint8_t ColorAttachment0DestinationRGBBlendFactor; 48 uint8_t ColorAttachment0SourceAlphaBlendFactor; 49 uint8_t ColorAttachment0SourceRGBBlendFactor; 50 }; 51 52 struct RenderPipelineState { 53 void *RenderPipelineState; 54 const char *Error; 55 }; 56 57 struct ClearColor { 58 double Red; 59 double Green; 60 double Blue; 61 double Alpha; 62 }; 63 64 struct RenderPassDescriptor { 65 uint8_t ColorAttachment0LoadAction; 66 uint8_t ColorAttachment0StoreAction; 67 struct ClearColor ColorAttachment0ClearColor; 68 void *ColorAttachment0Texture; 69 }; 70 71 struct TextureDescriptor { 72 uint16_t TextureType; 73 uint16_t PixelFormat; 74 uint_t Width; 75 uint_t Height; 76 uint8_t StorageMode; 77 uint8_t Usage; 78 }; 79 80 struct Origin { 81 uint_t X; 82 uint_t Y; 83 uint_t Z; 84 }; 85 86 struct Size { 87 uint_t Width; 88 uint_t Height; 89 uint_t Depth; 90 }; 91 92 struct Region { 93 struct Origin Origin; 94 struct Size Size; 95 }; 96 97 struct Viewport { 98 double OriginX; 99 double OriginY; 100 double Width; 101 double Height; 102 double ZNear; 103 double ZFar; 104 }; 105 106 struct ScissorRect { 107 uint_t X; 108 uint_t Y; 109 uint_t Width; 110 uint_t Height; 111 }; 112 113 struct Device CreateSystemDefaultDevice(); 114 struct Devices CopyAllDevices(); 115 116 uint8_t Device_SupportsFeatureSet(void *device, uint16_t featureSet); 117 void *Device_MakeCommandQueue(void *device); 118 struct Library Device_MakeLibrary(void *device, const char *source, 119 size_t sourceLength); 120 struct RenderPipelineState 121 Device_MakeRenderPipelineState(void *device, 122 struct RenderPipelineDescriptor descriptor); 123 void *Device_MakeBufferWithBytes(void *device, const void *bytes, size_t length, 124 uint16_t options); 125 void *Device_MakeBufferWithLength(void *device, size_t length, 126 uint16_t options); 127 void *Device_MakeTexture(void *device, struct TextureDescriptor descriptor); 128 129 void CommandQueue_Release(void *commandQueue); 130 void *CommandQueue_MakeCommandBuffer(void *commandQueue); 131 132 void CommandBuffer_Release(void *commandBuffer); 133 void CommandBuffer_PresentDrawable(void *commandBuffer, void *drawable); 134 void CommandBuffer_Commit(void *commandBuffer); 135 void CommandBuffer_WaitUntilCompleted(void *commandBuffer); 136 void * 137 CommandBuffer_MakeRenderCommandEncoder(void *commandBuffer, 138 struct RenderPassDescriptor descriptor); 139 void *CommandBuffer_MakeBlitCommandEncoder(void *commandBuffer); 140 141 void CommandEncoder_EndEncoding(void *commandEncoder); 142 143 void RenderCommandEncoder_Release(void *renderCommandEncoder); 144 void RenderCommandEncoder_SetRenderPipelineState(void *renderCommandEncoder, 145 void *renderPipelineState); 146 void RenderCommandEncoder_SetViewport(void *renderCommandEncoder, 147 struct Viewport viewport); 148 void RenderCommandEncoder_SetScissorRect(void *renderCommandEncoder, 149 struct ScissorRect scissorRect); 150 void RenderCommandEncoder_SetVertexBuffer(void *renderCommandEncoder, 151 void *buffer, uint_t offset, 152 uint_t index); 153 void RenderCommandEncoder_SetVertexBytes(void *renderCommandEncoder, 154 const void *bytes, size_t length, 155 uint_t index); 156 void RenderCommandEncoder_SetFragmentBytes(void *renderCommandEncoder, 157 const void *bytes, size_t length, 158 uint_t index); 159 void RenderCommandEncoder_SetBlendColor(void *renderCommandEncoder, float red, 160 float green, float blue, float alpha); 161 void RenderCommandEncoder_SetFragmentTexture(void *renderCommandEncoder, 162 void *texture, uint_t index); 163 void RenderCommandEncoder_DrawPrimitives(void *renderCommandEncoder, 164 uint8_t primitiveType, 165 uint_t vertexStart, 166 uint_t vertexCount); 167 void RenderCommandEncoder_DrawIndexedPrimitives( 168 void *renderCommandEncoder, uint8_t primitiveType, uint_t indexCount, 169 uint8_t indexType, void *indexBuffer, uint_t indexBufferOffset); 170 171 void BlitCommandEncoder_Synchronize(void *blitCommandEncoder, void *resource); 172 void BlitCommandEncoder_SynchronizeTexture(void *blitCommandEncoder, 173 void *texture, uint_t slice, 174 uint_t level); 175 void BlitCommandEncoder_CopyFromTexture( 176 void *blitCommandEncoder, void *sourceTexture, uint_t sourceSlice, 177 uint_t sourceLevel, struct Origin sourceOrigin, struct Size sourceSize, 178 void *destinationTexture, uint_t destinationSlice, uint_t destinationLevel, 179 struct Origin destinationOrigin); 180 181 void *Library_MakeFunction(void *library, const char *name); 182 183 void Texture_Release(void *texture); 184 void Texture_GetBytes(void *texture, void *pixelBytes, size_t bytesPerRow, 185 struct Region region, uint_t level); 186 void Texture_ReplaceRegion(void *texture, struct Region region, uint_t level, 187 void *pixelBytes, uint_t bytesPerRow); 188 int Texture_Width(void *texture); 189 int Texture_Height(void *texture); 190 191 void Buffer_CopyToContents(void *buffer, void *data, size_t lengthInBytes); 192 void Buffer_Retain(void *buffer); 193 void Buffer_Release(void *buffer); 194 void Function_Release(void *function); 195 void RenderPipelineState_Release(void *renderPipelineState);