diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index cb683aefde7..4f189312306 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define BACKGROUND_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto backgroundShaderCommon = R"( enum { idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -72,19 +74,10 @@ union BackgroundDrawableUnionUBO { BackgroundPatternDrawableUBO backgroundPatternDrawableUBO; }; -)" - -template <> -struct ShaderSource { - static constexpr auto name = "BackgroundShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +)"_cts; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +constexpr auto backgroundShaderSource = backgroundShaderCommon + R"( - static constexpr auto source = BACKGROUND_SHADER_COMMON R"( #include using namespace metal; @@ -115,20 +108,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(props.color * props.opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "BackgroundPatternShader"; +struct ShaderSource { + static constexpr auto name = "BackgroundShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = backgroundShaderSource.as_string_view(); +}; + +constexpr auto backgroundPatternShaderSource = backgroundShaderCommon + R"( - static constexpr auto source = BACKGROUND_SHADER_COMMON R"( #include using namespace metal; @@ -186,7 +182,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.mix) * props.opacity); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "BackgroundPatternShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = backgroundPatternShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index 2a95a763fe1..44c89e56df4 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define CIRCLE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto circleShaderPrelude = R"( enum { idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -51,19 +53,10 @@ struct alignas(16) CircleEvaluatedPropsUBO { }; static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "CircleShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto circleShaderSource = circleShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = CIRCLE_SHADER_PRELUDE R"( struct VertexStage { short2 position [[attribute(circleUBOCount + 0)]]; @@ -251,7 +244,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(opacity_t * mix(color * opacity, stroke_color * stroke_opacity, color_t)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "CircleShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = circleShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index 580c1ad9efd..69c7b432829 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -2,10 +2,13 @@ #include #include +#include namespace mbgl { namespace shaders { +using mbgl::util::operator""_cts; + struct alignas(16) ClipUBO { /* 0 */ std::array matrix; /* 64 */ std::uint32_t stencil_ref; @@ -16,8 +19,7 @@ struct alignas(16) ClipUBO { }; static_assert(sizeof(ClipUBO) == 5 * 16); -#define CLIPPING_MASK_SHADER_PRELUDE \ - R"( +constexpr auto clippingMaskShaderPrelude = R"( #include using namespace metal; @@ -37,19 +39,10 @@ struct alignas(16) ClipUBO { }; static_assert(sizeof(ClipUBO) == 5 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "ClippingMaskProgram"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto clippingMaskShaderSource = clippingMaskShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = CLIPPING_MASK_SHADER_PRELUDE R"( struct VertexStage { short2 position [[attribute(clippingMaskUBOCount + 0)]]; }; @@ -71,7 +64,19 @@ FragmentStage vertex vertexMain(VertexStage in [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]]) { return half4(1.0); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "ClippingMaskProgram"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = clippingMaskShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index 82581e74d37..8e8e037d70d 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto customSymbolIconShaderPrelude = R"( enum { idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -31,19 +33,10 @@ struct alignas(16) CustomSymbolIconDrawableUBO { }; static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "CustomSymbolIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto customSymbolIconShaderSource = customSymbolIconShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"( struct VertexStage { float2 a_pos [[attribute(customSymbolUBOCount + 0)]]; float2 a_tex [[attribute(customSymbolUBOCount + 1)]]; @@ -107,7 +100,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(image.sample(image_sampler, float2(in.tex))); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "CustomSymbolIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = customSymbolIconShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 633c6a0a985..7d9352c2f22 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define DEBUG_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto debugShaderPrelude = R"( enum { idDebugUBO = drawableReservedUBOCount, @@ -26,19 +28,9 @@ struct alignas(16) DebugUBO { }; static_assert(sizeof(DebugUBO) == 6 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "DebugShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = DEBUG_SHADER_PRELUDE R"( +constexpr auto debugShaderSource = debugShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(debugUBOCount + 0)]]; @@ -73,7 +65,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], float4 color = mix(debug.color, overlay_color, overlay_color.a); return half4(color); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "DebugShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = debugShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index b589a8dca4d..b7cb6c9d70b 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define FILL_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto fillShaderCommon = R"( enum { idFillDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -139,19 +141,9 @@ union FillTilePropsUnionUBO { FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO; }; -)" - -template <> -struct ShaderSource { - static constexpr auto name = "FillShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = FILL_SHADER_COMMON R"( +constexpr auto fillShaderSource = fillShaderCommon + R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -212,12 +204,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillOutlineShader"; +struct ShaderSource { + static constexpr auto name = "FillShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -225,7 +216,11 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = FILL_SHADER_COMMON R"( + static constexpr auto source = fillShaderSource.as_string_view(); +}; + +constexpr auto fillOutlineShaderSource = fillShaderCommon + R"( + struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; float4 outline_color [[attribute(fillUBOCount + 1)]]; @@ -289,20 +284,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillPatternShader"; +struct ShaderSource { + static constexpr auto name = "FillOutlineShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = fillOutlineShaderSource.as_string_view(); +}; + +constexpr auto fillPatternShaderSource = fillShaderCommon + R"( - static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -430,12 +428,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.fade) * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillOutlinePatternShader"; +struct ShaderSource { + static constexpr auto name = "FillPatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -443,7 +440,10 @@ struct ShaderSource instanceAttributes{}; static const std::array textures; - static constexpr auto source = FILL_SHADER_COMMON R"( + static constexpr auto source = fillPatternShaderSource.as_string_view(); +}; + +constexpr auto fillOutlinePatternShaderSource = fillShaderCommon + R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -584,20 +584,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.fade) * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillOutlineTriangulatedShader"; +struct ShaderSource { + static constexpr auto name = "FillOutlinePatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = fillOutlinePatternShaderSource.as_string_view(); +}; + +constexpr auto fillOutlineTriangulatedShaderSource = fillShaderCommon + R"( - static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(fillUBOCount + 0)]]; uchar4 data [[attribute(fillUBOCount + 1)]]; @@ -665,7 +668,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(props.outline_color * (alpha * props.opacity)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "FillOutlineTriangulatedShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = fillOutlineTriangulatedShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index 4a5e05663f3..940f1c100b8 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define FILL_EXTRUSION_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto fillExtrusionShaderCommon = R"( enum { idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -62,19 +64,10 @@ struct alignas(16) FillExtrusionPropsUBO { }; static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "FillExtrusionShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto fillExtrusionShaderSource = fillExtrusionShaderCommon + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"( struct VertexStage { short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]]; @@ -180,20 +173,23 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]]) { return { in.color/*, in.position.z*/ }; } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillExtrusionPatternShader"; +struct ShaderSource { + static constexpr auto name = "FillExtrusionShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = fillExtrusionShaderSource.as_string_view(); +}; + +constexpr auto fillExtrusionPatternShaderSource = fillExtrusionShaderCommon + R"( - static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"( struct VertexStage { short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]]; @@ -364,7 +360,19 @@ fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/}; } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "FillExtrusionPatternShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = fillExtrusionPatternShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index 81e4c25e4ba..e791eef91a0 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HEATMAP_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto heatmapShaderPrelude = R"( enum { idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -38,19 +40,9 @@ struct alignas(16) HeatmapEvaluatedPropsUBO { }; static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "HeatmapShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = HEATMAP_SHADER_PRELUDE R"( +constexpr auto heatmapShaderSource = heatmapShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(heatmapUBOCount + 0)]]; @@ -141,7 +133,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(val, 1.0, 1.0, 1.0); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HeatmapShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = heatmapShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index e32b2fdb53d..f614b54517d 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HEATMAP_TEXTURE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto heatmapTextureShaderPrelude = R"( enum { idHeatmapTexturePropsUBO = drawableReservedUBOCount, @@ -25,19 +27,9 @@ struct alignas(16) HeatmapTexturePropsUBO { }; static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "HeatmapTextureShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = HEATMAP_TEXTURE_SHADER_PRELUDE R"( +constexpr auto heatmapTextureShaderSource = heatmapTextureShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(heatmapTextureUBOCount + 0)]]; @@ -76,7 +68,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], float4 color = color_ramp.sample(color_ramp_sampler, float2(t, 0.5)); return half4(color * props.opacity); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HeatmapTextureShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = heatmapTextureShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index 39e5c74135e..57984d1f033 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HILLSHADE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto hillshadeShaderPrelude = R"( enum { idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -39,19 +41,9 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { }; static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "HillshadeShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = HILLSHADE_SHADER_PRELUDE R"( +constexpr auto hillshadeShaderSource = hillshadeShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(hillshadeUBOCount + 0)]]; @@ -129,7 +121,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HillshadeShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = hillshadeShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 8b3770b4d61..1f736503fad 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HILLSHADE_PREPARE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto hillshadePrepareShaderPrelude = R"( enum { idHillshadePrepareDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -31,19 +33,10 @@ struct alignas(16) HillshadePrepareTilePropsUBO { }; static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "HillshadePrepareShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto hillshadePrepareShaderSource = hillshadePrepareShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = HILLSHADE_PREPARE_SHADER_PRELUDE R"( struct VertexStage { short2 pos [[attribute(hillshadePrepareUBOCount + 0)]]; short2 texture_pos [[attribute(hillshadePrepareUBOCount + 1)]]; @@ -138,7 +131,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HillshadePrepareShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = hillshadePrepareShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index b95c3d0c666..1f1991a3561 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define LINE_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto lineShaderCommon = R"( enum { idLineDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -171,19 +173,10 @@ union LineTilePropsUnionUBO { LineSDFTilePropsUBO lineSDFTilePropsUBO; }; -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "LineShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto lineShaderSource = lineShaderCommon + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -348,20 +341,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "LineGradientShader"; +struct ShaderSource { + static constexpr auto name = "LineShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = lineShaderSource.as_string_view(); +}; + +constexpr auto lineGradientShaderSource = lineShaderCommon + R"( - static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -513,20 +509,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "LinePatternShader"; +struct ShaderSource { + static constexpr auto name = "LineGradientShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = LINE_SHADER_COMMON R"( + static constexpr auto source = lineGradientShaderSource.as_string_view(); +}; + +constexpr auto linePatternShaderSource = lineShaderCommon + R"( + struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -748,12 +747,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * alpha * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "LineSDFShader"; +struct ShaderSource { + static constexpr auto name = "LinePatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -761,7 +759,11 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = LINE_SHADER_COMMON R"( + static constexpr auto source = linePatternShaderSource.as_string_view(); +}; + +constexpr auto lineSDFShaderSource = lineShaderCommon + R"( + struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -967,7 +969,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "LineSDFShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = lineSDFShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index 22b1e995512..74167e8997f 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define RASTER_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto rasterShaderPrelude = R"( enum { idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -40,19 +42,9 @@ struct alignas(16) RasterEvaluatedPropsUBO { }; static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "RasterShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = RASTER_SHADER_PRELUDE R"( +constexpr auto rasterShaderSource = rasterShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(rasterUBOCount + 0)]]; @@ -131,7 +123,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(half3(mix(high_vec, low_vec, rgb) * color.a), color.a); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "RasterShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = rasterShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp index e3e9bcf9158..6f1a0c41794 100644 --- a/include/mbgl/shaders/mtl/symbol.hpp +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define SYMBOL_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto symbolShaderCommon = R"( enum { idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -71,19 +73,10 @@ struct alignas(16) SymbolEvaluatedPropsUBO { }; static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "SymbolIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto symbolIconShaderSource = symbolShaderCommon + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = SYMBOL_SHADER_COMMON R"( struct VertexStage { float4 pos_offset [[attribute(symbolUBOCount + 0)]]; float4 data [[attribute(symbolUBOCount + 1)]]; @@ -206,20 +199,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(image.sample(image_sampler, float2(in.tex)) * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "SymbolSDFIconShader"; +struct ShaderSource { + static constexpr auto name = "SymbolIconShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = SYMBOL_SHADER_COMMON R"( + static constexpr auto source = symbolIconShaderSource.as_string_view(); +}; + +constexpr auto symbolSDFIconShaderSource = symbolShaderCommon + R"( + struct VertexStage { float4 pos_offset [[attribute(symbolUBOCount + 0)]]; float4 data [[attribute(symbolUBOCount + 1)]]; @@ -413,20 +409,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity * in.fade_opacity)); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "SymbolTextAndIconShader"; +struct ShaderSource { + static constexpr auto name = "SymbolSDFIconShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = symbolSDFIconShaderSource.as_string_view(); +}; + +constexpr auto symbolTextAndIconShaderSource = symbolShaderCommon + R"( - static constexpr auto source = SYMBOL_SHADER_COMMON R"( #define SDF 1.0 #define ICON 0.0 @@ -637,7 +636,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity * in.fade_opacity)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "SymbolTextAndIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = symbolTextAndIconShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index ba18276c5c6..7b1612834d5 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define WIDEVECTOR_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto wideVectorShaderPrelude = R"( enum { idWideVectorUniformsUBO = idDrawableReservedVertexOnlyUBO, @@ -16,19 +18,10 @@ enum { wideVectorUBOCount }; -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "WideVectorShader"; - static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; - static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; +constexpr auto wideVectorShaderSource = wideVectorShaderPrelude + R"( - static const std::array attributes; - static const std::array instanceAttributes; - static const std::array textures; - - static constexpr auto source = WIDEVECTOR_SHADER_PRELUDE R"( #include namespace WhirlyKitShader @@ -579,7 +572,19 @@ fragment float4 fragmentTri_wideVecPerf( return vert.color * float4(1,1,1,edgeAlpha * patternAlpha * roundAlpha); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "WideVectorShader"; + static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; + static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; + + static const std::array attributes; + static const std::array instanceAttributes; + static const std::array textures; + + static constexpr auto source = wideVectorShaderSource.as_string_view(); }; } // namespace shaders