Skip to content

Commit

Permalink
in the Metal samples, SG_PIXELFORMAT_NONE/DEPTH/DEPTH_STENCIL as dept…
Browse files Browse the repository at this point in the history
…h buffer formats
  • Loading branch information
floooh committed Mar 1, 2024
1 parent 869367e commit 023a08f
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion metal/arraytex-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ static void shutdown() {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Array Texture (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "arraytex-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/binshader-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ static void shutdown() {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Shader Bytecode (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "binshader-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/blend-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,5 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Blend (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH_STENCIL, "blend-metal", init, frame, shutdown);
}
2 changes: 1 addition & 1 deletion metal/bufferoffsets-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ static void shutdown(void) {
}

int main() {
osx_start(640, 480, 1, "Sokol Buffer Offsets (Metal)", init, frame, shutdown);
osx_start(640, 480, 1, SG_PIXELFORMAT_NONE, "bufferoffsets-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/clear-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ static void shutdown(void) {
}

int main() {
osx_start(640, 480, 1, "Sokol Clear (Metal)", init, frame, shutdown);
osx_start(640, 480, 1, SG_PIXELFORMAT_NONE, "clear-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/cube-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Cube (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "cube-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/dyntex-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void shutdown(void) {
}

int main() {
osx_start(DISPLAY_WIDTH, DISPLAY_HEIGHT, SAMPLE_COUNT, "Dynamic Texture (Metal)", init, frame, shutdown);
osx_start(DISPLAY_WIDTH, DISPLAY_HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "dyntex-metal", init, frame, shutdown);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion metal/imgui-metal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ void shutdown() {
}

int main() {
osx_start(WIDTH, HEIGHT, 1, "Sokol Dear ImGui (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, 1, SG_PIXELFORMAT_NONE, "Sokol Dear ImGui (Metal)", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/inject-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,6 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Resource Injection (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH_STENCIL, "inject-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/instancing-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Instancing (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "instancing-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/mipmap-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,5 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Mipmapping (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "mipmap-metal", init, frame, shutdown);
}
2 changes: 1 addition & 1 deletion metal/mrt-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,6 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol MRT (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "mrt-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/noninterleaved-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Non-Interleaved Vertex Data (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "noninterleaved-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/offscreen-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,6 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol Offscreen (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH_STENCIL, "offscreen-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/osxentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef void(*osx_mouse_pos_func)(float x, float y);
typedef void(*osx_mouse_wheel_func)(float v);

/* entry function */
extern void osx_start(int w, int h, int sample_count, const char* title, osx_init_func, osx_frame_func, osx_shutdown_func);
extern void osx_start(int w, int h, int sample_count, sg_pixel_format depth_format, const char* title, osx_init_func, osx_frame_func, osx_shutdown_func);
/* return an initialized sg_environment struct */
sg_environment osx_environment(void);
/* return an initialized sg_swapchain struct */
Expand Down
21 changes: 17 additions & 4 deletions metal/osxentry.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @interface SokolMTKView : MTKView
static int width;
static int height;
static int sample_count;
static sg_pixel_format depth_format;
static const char* window_title;
static osx_init_func init_func;
static osx_frame_func frame_func;
Expand Down Expand Up @@ -109,7 +110,17 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
[mtk_view setDelegate:mtk_view_delegate];
[mtk_view setDevice: mtl_device];
[mtk_view setColorPixelFormat:MTLPixelFormatBGRA8Unorm];
[mtk_view setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
switch (depth_format) {
case SG_PIXELFORMAT_DEPTH_STENCIL:
[mtk_view setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
break;
case SG_PIXELFORMAT_DEPTH:
[mtk_view setDepthStencilPixelFormat:MTLPixelFormatDepth32Float];
break;
default:
[mtk_view setDepthStencilPixelFormat:MTLPixelFormatInvalid];
break;
}
[mtk_view setSampleCount:(NSUInteger)sample_count];
#if !TARGET_OS_IPHONE
[window setContentView:mtk_view];
Expand Down Expand Up @@ -305,10 +316,12 @@ - (void)scrollWheel:(NSEvent*)event {
@end

//------------------------------------------------------------------------------
void osx_start(int w, int h, int smp_count, const char* title, osx_init_func ifun, osx_frame_func ffun, osx_shutdown_func sfun) {
void osx_start(int w, int h, int smp_count, sg_pixel_format depth_fmt, const char* title, osx_init_func ifun, osx_frame_func ffun, osx_shutdown_func sfun) {
assert((depth_fmt == SG_PIXELFORMAT_DEPTH_STENCIL) || (depth_fmt == SG_PIXELFORMAT_DEPTH) || (depth_fmt == SG_PIXELFORMAT_NONE));
width = w;
height = h;
sample_count = smp_count;
depth_format = depth_fmt;
window_title = title;
init_func = ifun;
frame_func = ffun;
Expand Down Expand Up @@ -340,7 +353,7 @@ sg_environment osx_environment(void) {
.defaults = {
.sample_count = sample_count,
.color_format = SG_PIXELFORMAT_BGRA8,
.depth_format = SG_PIXELFORMAT_DEPTH_STENCIL,
.depth_format = depth_format,
},
.metal = {
.device = (__bridge const void*) mtl_device,
Expand All @@ -354,7 +367,7 @@ sg_swapchain osx_swapchain(void) {
.height = (int) [mtk_view drawableSize].height,
.sample_count = sample_count,
.color_format = SG_PIXELFORMAT_BGRA8,
.depth_format = SG_PIXELFORMAT_DEPTH_STENCIL,
.depth_format = depth_format,
.metal = {
.current_drawable = (__bridge const void*) [mtk_view currentDrawable],
.depth_stencil_texture = (__bridge const void*) [mtk_view depthStencilTexture],
Expand Down
2 changes: 1 addition & 1 deletion metal/quad-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ static void shutdown(void) {
}

int main() {
osx_start(640, 480, 1, "Sokol Quad (Metal)", init, frame, shutdown);
osx_start(640, 480, 1, SG_PIXELFORMAT_NONE, "quad-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/releasetest-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ static void shutdown(void) {
}

int main() {
osx_start(640, 480, 1, "Sokol Resource Stress (Metal)", init, frame, shutdown);
osx_start(640, 480, 1, SG_PIXELFORMAT_DEPTH_STENCIL, "releasetest-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/texcube-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ static void shutdown(void) {
}

int main() {
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, "Sokol TexCube (Metal)", init, frame, shutdown);
osx_start(WIDTH, HEIGHT, SAMPLE_COUNT, SG_PIXELFORMAT_DEPTH, "texcube-metal", init, frame, shutdown);
return 0;
}
2 changes: 1 addition & 1 deletion metal/triangle-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ static void shutdown(void) {
}

int main() {
osx_start(640, 480, 1, "Sokol Triangle (Metal)", init, frame, shutdown);
osx_start(640, 480, 1, SG_PIXELFORMAT_NONE, "triangle-metal", init, frame, shutdown);
return 0;
}

0 comments on commit 023a08f

Please sign in to comment.