Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing metal on my macs. My dear Mac Mini does not support it
#include "SDL2.framework/Headers/SDL.h"
#define sdl2_guard(__expr) \
if ((__expr) != 0) { \
fprintf(stderr, "SDL Error: '%s'\n", SDL_GetError()); \
assert(0); \
}
#include <assert.h>
// Metal isn't supposed to support pre-GCN AMD graphics cards
// My metal Mini has such AMD HD 6600M. GCN starts with 7000
int main(int argc, char **argv)
{
sdl2_guard(SDL_Init(SDL_INIT_VIDEO));
SDL_Window *window = SDL_CreateWindow("metal-test", 20, 20, 500, 500, 0);
sdl2_guard(window == NULL? -1:0);
SDL_Renderer *renderer;
{
int num_drivers = SDL_GetNumRenderDrivers();
for (int i = 0; i < num_drivers; i++) {
SDL_RendererInfo renderer_info;
sdl2_guard(SDL_GetRenderDriverInfo(i, &renderer_info));
printf("driver[%d] = SDL_RendererInfo {\n", i);
printf(" name = \"%s\";\n", renderer_info.name);
printf(" flags = 0%s%s%s%s;\n",
renderer_info.flags & SDL_RENDERER_SOFTWARE? " | SDL_RENDERER_SOFTWARE" : "",
renderer_info.flags & SDL_RENDERER_ACCELERATED? " | SDL_RENDERER_ACCELERATED" : "",
renderer_info.flags & SDL_RENDERER_PRESENTVSYNC? " | SDL_RENDERER_PRESENTVSYNC" : "",
renderer_info.flags & SDL_RENDERER_TARGETTEXTURE? " | SDL_RENDERER_TARGETTEXTURE" : "");
printf(" // ...\n");
printf("}\n");
if (0 == strcmp("metal", renderer_info.name)) {
renderer = SDL_CreateRenderer(window, i, renderer_info.flags);
sdl2_guard(renderer == NULL? -1:0);
}
}
}
int must_quit = 0;
while (!must_quit) {
SDL_Event event;
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
must_quit = 1;
}
}
SDL_SetRenderDrawColor(renderer, 50, 50, 52, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 40, 80, 12, 255);
SDL_RenderDrawRect(renderer, &(SDL_Rect){.x = 20, .y = 20, .w = 460, .h = 460 });
SDL_RenderPresent(renderer);
}
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.