mtl.h (6524B)
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 Device CreateSystemDefaultDevice(); 107 struct Devices CopyAllDevices(); 108 109 uint8_t Device_SupportsFeatureSet(void *device, uint16_t featureSet); 110 void *Device_MakeCommandQueue(void *device); 111 struct Library Device_MakeLibrary(void *device, const char *source, 112 size_t sourceLength); 113 struct RenderPipelineState 114 Device_MakeRenderPipelineState(void *device, 115 struct RenderPipelineDescriptor descriptor); 116 void *Device_MakeBufferWithBytes(void *device, const void *bytes, size_t length, 117 uint16_t options); 118 void *Device_MakeBufferWithLength(void *device, size_t length, 119 uint16_t options); 120 void *Device_MakeTexture(void *device, struct TextureDescriptor descriptor); 121 122 void CommandQueue_Release(void *commandQueue); 123 void *CommandQueue_MakeCommandBuffer(void *commandQueue); 124 125 void CommandBuffer_Release(void *commandBuffer); 126 void CommandBuffer_PresentDrawable(void *commandBuffer, void *drawable); 127 void CommandBuffer_Commit(void *commandBuffer); 128 void CommandBuffer_WaitUntilCompleted(void *commandBuffer); 129 void * 130 CommandBuffer_MakeRenderCommandEncoder(void *commandBuffer, 131 struct RenderPassDescriptor descriptor); 132 void *CommandBuffer_MakeBlitCommandEncoder(void *commandBuffer); 133 134 void CommandEncoder_EndEncoding(void *commandEncoder); 135 136 void RenderCommandEncoder_Release(void *renderCommandEncoder); 137 void RenderCommandEncoder_SetRenderPipelineState(void *renderCommandEncoder, 138 void *renderPipelineState); 139 void RenderCommandEncoder_SetViewport(void *renderCommandEncoder, 140 struct Viewport viewport); 141 void RenderCommandEncoder_SetVertexBuffer(void *renderCommandEncoder, 142 void *buffer, uint_t offset, 143 uint_t index); 144 void RenderCommandEncoder_SetVertexBytes(void *renderCommandEncoder, 145 const void *bytes, size_t length, 146 uint_t index); 147 void RenderCommandEncoder_SetFragmentBytes(void *renderCommandEncoder, 148 const void *bytes, size_t length, 149 uint_t index); 150 void RenderCommandEncoder_SetBlendColor(void *renderCommandEncoder, float red, 151 float green, float blue, float alpha); 152 void RenderCommandEncoder_SetFragmentTexture(void *renderCommandEncoder, 153 void *texture, uint_t index); 154 void RenderCommandEncoder_DrawPrimitives(void *renderCommandEncoder, 155 uint8_t primitiveType, 156 uint_t vertexStart, 157 uint_t vertexCount); 158 void RenderCommandEncoder_DrawIndexedPrimitives( 159 void *renderCommandEncoder, uint8_t primitiveType, uint_t indexCount, 160 uint8_t indexType, void *indexBuffer, uint_t indexBufferOffset); 161 162 void BlitCommandEncoder_Synchronize(void *blitCommandEncoder, void *resource); 163 void BlitCommandEncoder_SynchronizeTexture(void *blitCommandEncoder, 164 void *texture, uint_t slice, 165 uint_t level); 166 void BlitCommandEncoder_CopyFromTexture( 167 void *blitCommandEncoder, void *sourceTexture, uint_t sourceSlice, 168 uint_t sourceLevel, struct Origin sourceOrigin, struct Size sourceSize, 169 void *destinationTexture, uint_t destinationSlice, uint_t destinationLevel, 170 struct Origin destinationOrigin); 171 172 void *Library_MakeFunction(void *library, const char *name); 173 174 void Texture_Release(void *texture); 175 void Texture_GetBytes(void *texture, void *pixelBytes, size_t bytesPerRow, 176 struct Region region, uint_t level); 177 void Texture_ReplaceRegion(void *texture, struct Region region, uint_t level, 178 void *pixelBytes, uint_t bytesPerRow); 179 int Texture_Width(void *texture); 180 int Texture_Height(void *texture); 181 182 void Buffer_CopyToContents(void *buffer, void *data, size_t lengthInBytes); 183 void Buffer_Retain(void *buffer); 184 void Buffer_Release(void *buffer); 185 void Function_Release(void *function); 186 void RenderPipelineState_Release(void *renderPipelineState);