-
-
Save hammanandre/af4417f62c8cd3d487e78c44cf71db31 to your computer and use it in GitHub Desktop.
Revisions
-
gcatlin revised this gist
Jul 14, 2020 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ // // cc sdl-metal-example.m `sdl2-config --cflags --libs` -framework Metal -framework QuartzCore && ./a.out // #include <SDL.h> #import <Metal/Metal.h> #import <QuartzCore/CAMetalLayer.h> @@ -14,7 +14,6 @@ int main (int argc, char *args[]) const CAMetalLayer *swapchain = (__bridge CAMetalLayer *)SDL_RenderGetMetalLayer(renderer); const id<MTLDevice> gpu = swapchain.device; const id<MTLCommandQueue> queue = [gpu newCommandQueue]; MTLClearColor color = MTLClearColorMake(0, 0, 0, 1); bool quit = false; @@ -46,6 +45,7 @@ int main (int argc, char *args[]) } } SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); -
gcatlin renamed this gist
Nov 4, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // // cc sdl-metal-example.m -framework SDL2 -framework Metal -framework QuartzCore // #include <SDL2/SDL.h> #import <Metal/Metal.h> -
gcatlin revised this gist
Nov 4, 2018 . 1 changed file with 16 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // // cc main.m -framework SDL2 -framework Metal -framework QuartzCore // #include <SDL2/SDL.h> #import <Metal/Metal.h> @@ -9,19 +9,14 @@ int main (int argc, char *args[]) { SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_Window *window = SDL_CreateWindow("SDL Metal", -1, -1, 640, 480, SDL_WINDOW_ALLOW_HIGHDPI); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); const CAMetalLayer *swapchain = (__bridge CAMetalLayer *)SDL_RenderGetMetalLayer(renderer); const id<MTLDevice> gpu = swapchain.device; const id<MTLCommandQueue> queue = [gpu newCommandQueue]; SDL_DestroyRenderer(renderer); MTLClearColor color = MTLClearColorMake(0, 0, 0, 1); bool quit = false; SDL_Event e; @@ -33,16 +28,18 @@ int main (int argc, char *args[]) } @autoreleasepool { id<CAMetalDrawable> surface = [swapchain nextDrawable]; color.red = (color.red > 1.0) ? 0 : color.red + 0.01; MTLRenderPassDescriptor *pass = [MTLRenderPassDescriptor renderPassDescriptor]; pass.colorAttachments[0].clearColor = color; pass.colorAttachments[0].loadAction = MTLLoadActionClear; pass.colorAttachments[0].storeAction = MTLStoreActionStore; pass.colorAttachments[0].texture = surface.texture; id<MTLCommandBuffer> buffer = [queue commandBuffer]; id<MTLRenderCommandEncoder> encoder = [buffer renderCommandEncoderWithDescriptor:pass]; [encoder endEncoding]; [buffer presentDrawable:surface]; [buffer commit]; -
gcatlin revised this gist
Nov 2, 2018 . 1 changed file with 4 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,27 +1,21 @@ // // cc main.m -framework Metal -framework QuartzCore -framework SDL2 // #include <SDL2/SDL.h> #import <Metal/Metal.h> #import <QuartzCore/CAMetalLayer.h> int main (int argc, char *args[]) { SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_Window *window = SDL_CreateWindow("SDL Metal", -1, -1, 640, 480, 0); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); const CAMetalLayer *mtllayer = (__bridge CAMetalLayer *)SDL_RenderGetMetalLayer(renderer); SDL_DestroyRenderer(renderer); const id<MTLDevice> mtldevice = mtllayer.device; const id<MTLCommandQueue> mtlcmdqueue = [mtldevice newCommandQueue]; MTLRenderPassDescriptor *pass = [MTLRenderPassDescriptor renderPassDescriptor]; MTLRenderPassColorAttachmentDescriptor *ca = pass.colorAttachments[0]; ca.clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0); -
gcatlin created this gist
Nov 2, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ // // cc main.m -framework AppKit -framework Metal -framework QuartzCore -framework SDL2 // #include <SDL2/SDL.h> #import <AppKit/AppKit.h> #import <Metal/Metal.h> #import <QuartzCore/CAMetalLayer.h> int main (int argc, char *args[]) { const int w = 640; const int h = 480; SDL_SetHintWithPriority(SDL_HINT_RENDER_DRIVER, "metal", SDL_HINT_OVERRIDE); SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_Window *window = SDL_CreateWindow("SDL Metal", -1, -1, w, h, 0); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); const CAMetalLayer *mtllayer = (__bridge CAMetalLayer *)SDL_RenderGetMetalLayer(renderer); SDL_DestroyRenderer(renderer); const id<MTLDevice> mtldevice = mtllayer.device; const id<MTLCommandQueue> mtlcmdqueue = [mtldevice newCommandQueue]; MTLRenderPassDescriptor *pass = [MTLRenderPassDescriptor renderPassDescriptor]; MTLRenderPassColorAttachmentDescriptor *ca = pass.colorAttachments[0]; ca.clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0); ca.loadAction = MTLLoadActionClear; ca.storeAction = MTLStoreActionStore; bool quit = false; SDL_Event e; while (!quit) { while (SDL_PollEvent(&e) != 0) { switch (e.type) { case SDL_QUIT: quit = true; break; } } @autoreleasepool { id<MTLCommandBuffer> buffer = [mtlcmdqueue commandBuffer]; id<MTLRenderCommandEncoder> encoder = [buffer renderCommandEncoderWithDescriptor:pass]; id<CAMetalDrawable> surface = [mtllayer nextDrawable]; MTLRenderPassColorAttachmentDescriptor *ca = pass.colorAttachments[0]; MTLClearColor color = ca.clearColor; color.red = (color.red > 1.0) ? 0 : color.red + 0.01; ca.clearColor = color; ca.texture = surface.texture; [encoder endEncoding]; [buffer presentDrawable:surface]; [buffer commit]; } } SDL_DestroyWindow(window); SDL_Quit(); return 0; }