diff --git a/CMakeLists.txt b/CMakeLists.txt index f61ea5bf9..5664d36d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -927,7 +927,8 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/shader_manifest.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/prelude.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/background.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/background_ubo.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_background.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_fill.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/background_pattern.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/circle.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/clipping_mask.hpp diff --git a/include/mbgl/gfx/renderer_backend.hpp b/include/mbgl/gfx/renderer_backend.hpp index 48a50f99a..d1c9e7ea7 100644 --- a/include/mbgl/gfx/renderer_backend.hpp +++ b/include/mbgl/gfx/renderer_backend.hpp @@ -6,6 +6,9 @@ #include namespace mbgl { + +class ProgramParameters; + namespace gfx { class BackendScope; @@ -42,7 +45,7 @@ public: virtual Renderable& getDefaultRenderable() = 0; /// One-time shader initialization - virtual void initShaders(gfx::ShaderRegistry&) = 0; + virtual void initShaders(gfx::ShaderRegistry&, const ProgramParameters&) = 0; protected: virtual std::unique_ptr createContext() = 0; diff --git a/include/mbgl/gl/renderer_backend.hpp b/include/mbgl/gl/renderer_backend.hpp index 1e2474dbf..fa099529c 100644 --- a/include/mbgl/gl/renderer_backend.hpp +++ b/include/mbgl/gl/renderer_backend.hpp @@ -6,6 +6,9 @@ #include namespace mbgl { + +class ProgramParameters; + namespace gl { using ProcAddress = void (*)(); @@ -20,7 +23,7 @@ public: virtual void updateAssumedState() = 0; /// One-time shader initialization - void initShaders(gfx::ShaderRegistry&) override; + void initShaders(gfx::ShaderRegistry&, const ProgramParameters& programParameters) override; protected: std::unique_ptr createContext() override; diff --git a/include/mbgl/shaders/gl/background.hpp b/include/mbgl/shaders/gl/background.hpp index ba3d012d7..951f8824f 100644 --- a/include/mbgl/shaders/gl/background.hpp +++ b/include/mbgl/shaders/gl/background.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "BackgroundProgram"; static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; uniform mat4 u_matrix; diff --git a/include/mbgl/shaders/gl/background_pattern.hpp b/include/mbgl/shaders/gl/background_pattern.hpp index b3241b256..0ed1a77c0 100644 --- a/include/mbgl/shaders/gl/background_pattern.hpp +++ b/include/mbgl/shaders/gl/background_pattern.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "BackgroundPatternProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec2 u_pattern_size_a; uniform vec2 u_pattern_size_b; diff --git a/include/mbgl/shaders/gl/circle.hpp b/include/mbgl/shaders/gl/circle.hpp index 2999d5b56..27aede53c 100644 --- a/include/mbgl/shaders/gl/circle.hpp +++ b/include/mbgl/shaders/gl/circle.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "CircleProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform bool u_scale_with_map; uniform bool u_pitch_with_map; diff --git a/include/mbgl/shaders/gl/clipping_mask.hpp b/include/mbgl/shaders/gl/clipping_mask.hpp index 45c4903bd..2eed70b4c 100644 --- a/include/mbgl/shaders/gl/clipping_mask.hpp +++ b/include/mbgl/shaders/gl/clipping_mask.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "ClippingMaskProgram"; static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; uniform mat4 u_matrix; diff --git a/include/mbgl/shaders/gl/collision_box.hpp b/include/mbgl/shaders/gl/collision_box.hpp index 6a6c25aff..92b66b4ee 100644 --- a/include/mbgl/shaders/gl/collision_box.hpp +++ b/include/mbgl/shaders/gl/collision_box.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "CollisionBoxProgram"; static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; layout (location = 1) in vec2 a_anchor_pos; layout (location = 2) in vec2 a_extrude; diff --git a/include/mbgl/shaders/gl/collision_circle.hpp b/include/mbgl/shaders/gl/collision_circle.hpp index db07f5563..389441ff4 100644 --- a/include/mbgl/shaders/gl/collision_circle.hpp +++ b/include/mbgl/shaders/gl/collision_circle.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "CollisionCircleProgram"; static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; layout (location = 1) in vec2 a_anchor_pos; layout (location = 2) in vec2 a_extrude; diff --git a/include/mbgl/shaders/gl/debug.hpp b/include/mbgl/shaders/gl/debug.hpp index ae0661b6f..27a3d164a 100644 --- a/include/mbgl/shaders/gl/debug.hpp +++ b/include/mbgl/shaders/gl/debug.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "DebugProgram"; static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; out vec2 v_uv; diff --git a/include/mbgl/shaders/gl/drawable_background.hpp b/include/mbgl/shaders/gl/drawable_background.hpp new file mode 100644 index 000000000..7224363f2 --- /dev/null +++ b/include/mbgl/shaders/gl/drawable_background.hpp @@ -0,0 +1,37 @@ +// Generated code, do not modify this file! +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js + +#pragma once +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "BackgroundShader"; + static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; +layout (std140) uniform DrawableUBO { + mat4 u_matrix; +}; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); +} +)"; + static constexpr const char* fragment = R"(layout (std140) uniform BackgroundLayerUBO { + vec4 u_color; + float u_opacity; +}; + +void main() { + fragColor = u_color * u_opacity; +#ifdef OVERDRAW_INSPECTOR + fragColor = vec4(1.0); +#endif +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/gl/background_ubo.hpp b/include/mbgl/shaders/gl/drawable_fill.hpp similarity index 50% rename from include/mbgl/shaders/gl/background_ubo.hpp rename to include/mbgl/shaders/gl/drawable_fill.hpp index 49047d665..7995e8367 100644 --- a/include/mbgl/shaders/gl/background_ubo.hpp +++ b/include/mbgl/shaders/gl/drawable_fill.hpp @@ -1,3 +1,6 @@ +// Generated code, do not modify this file! +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js + #pragma once #include @@ -5,12 +8,9 @@ namespace mbgl { namespace shaders { template <> -struct ShaderSource { - static constexpr const char* vertex = R"(#version 300 es -precision highp float; - -layout (location = 0) in vec2 a_pos; - +struct ShaderSource { + static constexpr const char* name = "FillShader"; + static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; layout (std140) uniform DrawableUBO { mat4 u_matrix; }; @@ -19,19 +19,13 @@ void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); } )"; - static constexpr const char* fragment = R"(#version 300 es -precision highp float; - -layout (std140) uniform BackgroundLayerUBO { + static constexpr const char* fragment = R"(layout (std140) uniform BackgroundLayerUBO { vec4 u_color; float u_opacity; }; -out vec4 fragColor; - void main() { fragColor = u_color * u_opacity; - #ifdef OVERDRAW_INSPECTOR fragColor = vec4(1.0); #endif diff --git a/include/mbgl/shaders/gl/fill.hpp b/include/mbgl/shaders/gl/fill.hpp index f9d373f81..9c7115e23 100644 --- a/include/mbgl/shaders/gl/fill.hpp +++ b/include/mbgl/shaders/gl/fill.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "FillProgram"; static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; uniform mat4 u_matrix; diff --git a/include/mbgl/shaders/gl/fill_extrusion.hpp b/include/mbgl/shaders/gl/fill_extrusion.hpp index cfb5f4339..f33acaab1 100644 --- a/include/mbgl/shaders/gl/fill_extrusion.hpp +++ b/include/mbgl/shaders/gl/fill_extrusion.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "FillExtrusionProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec3 u_lightcolor; uniform lowp vec3 u_lightpos; diff --git a/include/mbgl/shaders/gl/fill_extrusion_pattern.hpp b/include/mbgl/shaders/gl/fill_extrusion_pattern.hpp index 30c3fb804..7bc4869af 100644 --- a/include/mbgl/shaders/gl/fill_extrusion_pattern.hpp +++ b/include/mbgl/shaders/gl/fill_extrusion_pattern.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "FillExtrusionPatternProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec2 u_pixel_coord_upper; uniform vec2 u_pixel_coord_lower; diff --git a/include/mbgl/shaders/gl/fill_outline.hpp b/include/mbgl/shaders/gl/fill_outline.hpp index b7f452e39..b9aa85a5b 100644 --- a/include/mbgl/shaders/gl/fill_outline.hpp +++ b/include/mbgl/shaders/gl/fill_outline.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "FillOutlineProgram"; static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; uniform mat4 u_matrix; diff --git a/include/mbgl/shaders/gl/fill_outline_pattern.hpp b/include/mbgl/shaders/gl/fill_outline_pattern.hpp index dcfb603f7..89843fa2e 100644 --- a/include/mbgl/shaders/gl/fill_outline_pattern.hpp +++ b/include/mbgl/shaders/gl/fill_outline_pattern.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "FillOutlinePatternProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec2 u_world; uniform vec2 u_pixel_coord_upper; diff --git a/include/mbgl/shaders/gl/fill_pattern.hpp b/include/mbgl/shaders/gl/fill_pattern.hpp index cea586577..958e4aec0 100644 --- a/include/mbgl/shaders/gl/fill_pattern.hpp +++ b/include/mbgl/shaders/gl/fill_pattern.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "FillPatternProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec2 u_pixel_coord_upper; uniform vec2 u_pixel_coord_lower; diff --git a/include/mbgl/shaders/gl/heatmap.hpp b/include/mbgl/shaders/gl/heatmap.hpp index c7a13c928..b9cbc23ac 100644 --- a/include/mbgl/shaders/gl/heatmap.hpp +++ b/include/mbgl/shaders/gl/heatmap.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "HeatmapProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform float u_extrude_scale; uniform float u_opacity; diff --git a/include/mbgl/shaders/gl/heatmap_texture.hpp b/include/mbgl/shaders/gl/heatmap_texture.hpp index dc89ad0ad..5b4f64d89 100644 --- a/include/mbgl/shaders/gl/heatmap_texture.hpp +++ b/include/mbgl/shaders/gl/heatmap_texture.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "HeatmapTextureProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec2 u_world; layout (location = 0) in vec2 a_pos; diff --git a/include/mbgl/shaders/gl/hillshade.hpp b/include/mbgl/shaders/gl/hillshade.hpp index 3ade4f435..2ba6e48fa 100644 --- a/include/mbgl/shaders/gl/hillshade.hpp +++ b/include/mbgl/shaders/gl/hillshade.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "HillshadeProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; layout (location = 0) in vec2 a_pos; diff --git a/include/mbgl/shaders/gl/hillshade_prepare.hpp b/include/mbgl/shaders/gl/hillshade_prepare.hpp index 4836ccf17..08f105c02 100644 --- a/include/mbgl/shaders/gl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/gl/hillshade_prepare.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "HillshadePrepareProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec2 u_dimension; diff --git a/include/mbgl/shaders/gl/line.hpp b/include/mbgl/shaders/gl/line.hpp index c140c70fa..feb93151b 100644 --- a/include/mbgl/shaders/gl/line.hpp +++ b/include/mbgl/shaders/gl/line.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "LineProgram"; static constexpr const char* vertex = R"(// floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/include/mbgl/shaders/gl/line_gradient.hpp b/include/mbgl/shaders/gl/line_gradient.hpp index c98f1746a..e95b8b80e 100644 --- a/include/mbgl/shaders/gl/line_gradient.hpp +++ b/include/mbgl/shaders/gl/line_gradient.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "LineGradientProgram"; static constexpr const char* vertex = R"( // the attribute conveying progress along a line is scaled to [0, 2^15) #define MAX_LINE_DISTANCE 32767.0 diff --git a/include/mbgl/shaders/gl/line_pattern.hpp b/include/mbgl/shaders/gl/line_pattern.hpp index c18c98250..ed31cc38b 100644 --- a/include/mbgl/shaders/gl/line_pattern.hpp +++ b/include/mbgl/shaders/gl/line_pattern.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "LinePatternProgram"; static constexpr const char* vertex = R"(// floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/include/mbgl/shaders/gl/line_sdf.hpp b/include/mbgl/shaders/gl/line_sdf.hpp index 62a34d7cf..6a595c71d 100644 --- a/include/mbgl/shaders/gl/line_sdf.hpp +++ b/include/mbgl/shaders/gl/line_sdf.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "LineSDFProgram"; static constexpr const char* vertex = R"(// floor(127 / 2) == 63.0 // the maximum allowed miter limit is 2.0 at the moment. the extrude normal is // stored in a byte (-128..127). we scale regular normals up to length 63, but diff --git a/include/mbgl/shaders/gl/prelude.hpp b/include/mbgl/shaders/gl/prelude.hpp index 822fd2b39..5a68fd845 100644 --- a/include/mbgl/shaders/gl/prelude.hpp +++ b/include/mbgl/shaders/gl/prelude.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "Prelude"; static constexpr const char* vertex = R"(#ifdef GL_ES precision highp float; #else diff --git a/include/mbgl/shaders/gl/raster.hpp b/include/mbgl/shaders/gl/raster.hpp index 7087a5480..0cc012ff0 100644 --- a/include/mbgl/shaders/gl/raster.hpp +++ b/include/mbgl/shaders/gl/raster.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "RasterProgram"; static constexpr const char* vertex = R"(uniform mat4 u_matrix; uniform vec2 u_tl_parent; uniform float u_scale_parent; diff --git a/include/mbgl/shaders/gl/shader_program_gl.hpp b/include/mbgl/shaders/gl/shader_program_gl.hpp index d571b8e5f..80f9b1fd9 100644 --- a/include/mbgl/shaders/gl/shader_program_gl.hpp +++ b/include/mbgl/shaders/gl/shader_program_gl.hpp @@ -6,6 +6,9 @@ #include namespace mbgl { + +class ProgramParameters; + namespace gl { class ShaderProgramGL final : public gfx::ShaderProgramBase { @@ -19,9 +22,11 @@ public: const std::string_view typeName() const noexcept override { return Name; } static std::shared_ptr create(Context&, - std::string_view name, - std::string_view vertexSource, - std::string_view fragmentSource) noexcept(false); + const ProgramParameters& programParameters, + const std::string& name, + const std::string& vertexSource, + const std::string& fragmentSource, + const std::string& additionalDefines = "") noexcept(false); const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; } diff --git a/include/mbgl/shaders/gl/symbol_icon.hpp b/include/mbgl/shaders/gl/symbol_icon.hpp index abfc29e51..121f98291 100644 --- a/include/mbgl/shaders/gl/symbol_icon.hpp +++ b/include/mbgl/shaders/gl/symbol_icon.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "SymbolIconProgram"; static constexpr const char* vertex = R"(const float PI = 3.141592653589793; layout (location = 0) in vec4 a_pos_offset; diff --git a/include/mbgl/shaders/gl/symbol_sdf_icon.hpp b/include/mbgl/shaders/gl/symbol_sdf_icon.hpp index babe133eb..b02a5f143 100644 --- a/include/mbgl/shaders/gl/symbol_sdf_icon.hpp +++ b/include/mbgl/shaders/gl/symbol_sdf_icon.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "SymbolSDFIconProgram"; static constexpr const char* vertex = R"(const float PI = 3.141592653589793; layout (location = 0) in vec4 a_pos_offset; diff --git a/include/mbgl/shaders/gl/symbol_sdf_text.hpp b/include/mbgl/shaders/gl/symbol_sdf_text.hpp index fc170dd58..4c07c61ea 100644 --- a/include/mbgl/shaders/gl/symbol_sdf_text.hpp +++ b/include/mbgl/shaders/gl/symbol_sdf_text.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "SymbolSDFTextProgram"; static constexpr const char* vertex = R"(const float PI = 3.141592653589793; layout (location = 0) in vec4 a_pos_offset; diff --git a/include/mbgl/shaders/gl/symbol_text_and_icon.hpp b/include/mbgl/shaders/gl/symbol_text_and_icon.hpp index a448b437b..af77b3f1b 100644 --- a/include/mbgl/shaders/gl/symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/gl/symbol_text_and_icon.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -9,6 +9,7 @@ namespace shaders { template <> struct ShaderSource { + static constexpr const char* name = "SymbolTextAndIconProgram"; static constexpr const char* vertex = R"(const float PI = 3.141592653589793; layout (location = 0) in vec4 a_pos_offset; diff --git a/include/mbgl/shaders/shader_manifest.hpp b/include/mbgl/shaders/shader_manifest.hpp index afa9da09a..78c629191 100644 --- a/include/mbgl/shaders/shader_manifest.hpp +++ b/include/mbgl/shaders/shader_manifest.hpp @@ -1,10 +1,12 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include #ifdef MBGL_RENDER_BACKEND_OPENGL +#include +#include #include #include #include @@ -32,6 +34,4 @@ #include #include #include - -#include #endif diff --git a/include/mbgl/shaders/shader_source.hpp b/include/mbgl/shaders/shader_source.hpp index 851f938e5..796537b3f 100644 --- a/include/mbgl/shaders/shader_source.hpp +++ b/include/mbgl/shaders/shader_source.hpp @@ -1,5 +1,5 @@ // Generated code, do not modify this file! -// Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js +// Generated on 2023-05-11T18:11:44.911Z by mwilsnd using shaders/generate_shader_code.js #pragma once #include @@ -11,6 +11,8 @@ namespace shaders { /// source code for the desired program and graphics back-end. enum class BuiltIn { None, + BackgroundShader, + FillShader, Prelude, BackgroundProgram, BackgroundPatternProgram, @@ -37,9 +39,7 @@ enum class BuiltIn { SymbolIconProgram, SymbolSDFTextProgram, SymbolSDFIconProgram, - SymbolTextAndIconProgram, - - BackgroundProgramUBO + SymbolTextAndIconProgram }; /// @brief Select shader source based on a program type and a desired @@ -53,6 +53,7 @@ struct ShaderSource; /// @brief A specialization of the ShaderSource template for no shader code. template <> struct ShaderSource { + static constexpr const char* name = ""; static constexpr const char* vertex = ""; static constexpr const char* fragment = ""; }; diff --git a/shaders/drawable.background.fragment.glsl b/shaders/drawable.background.fragment.glsl new file mode 100644 index 000000000..96a3eb219 --- /dev/null +++ b/shaders/drawable.background.fragment.glsl @@ -0,0 +1,11 @@ +layout (std140) uniform BackgroundLayerUBO { + vec4 u_color; + float u_opacity; +}; + +void main() { + fragColor = u_color * u_opacity; +#ifdef OVERDRAW_INSPECTOR + fragColor = vec4(1.0); +#endif +} diff --git a/shaders/drawable.background.vertex.glsl b/shaders/drawable.background.vertex.glsl new file mode 100644 index 000000000..0ab8901b0 --- /dev/null +++ b/shaders/drawable.background.vertex.glsl @@ -0,0 +1,8 @@ +layout (location = 0) in vec2 a_pos; +layout (std140) uniform DrawableUBO { + mat4 u_matrix; +}; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); +} diff --git a/shaders/drawable.fill.fragment.glsl b/shaders/drawable.fill.fragment.glsl new file mode 100644 index 000000000..96a3eb219 --- /dev/null +++ b/shaders/drawable.fill.fragment.glsl @@ -0,0 +1,11 @@ +layout (std140) uniform BackgroundLayerUBO { + vec4 u_color; + float u_opacity; +}; + +void main() { + fragColor = u_color * u_opacity; +#ifdef OVERDRAW_INSPECTOR + fragColor = vec4(1.0); +#endif +} diff --git a/shaders/drawable.fill.vertex.glsl b/shaders/drawable.fill.vertex.glsl new file mode 100644 index 000000000..0ab8901b0 --- /dev/null +++ b/shaders/drawable.fill.vertex.glsl @@ -0,0 +1,8 @@ +layout (location = 0) in vec2 a_pos; +layout (std140) uniform DrawableUBO { + mat4 u_matrix; +}; + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); +} diff --git a/shaders/generate_shader_code.js b/shaders/generate_shader_code.js index af48723bd..dba2fdc5b 100644 --- a/shaders/generate_shader_code.js +++ b/shaders/generate_shader_code.js @@ -243,11 +243,6 @@ JSON.parse(fs.readFileSync(path.join(shaderRoot, "manifest.json"))) ? pragmaMapConvertOnlyVertexArrays(vertexSource, pragmaMap, attribMap, "vertex") : pragmaMapConvert(vertexSource, pragmaMap, attribMap, "vertex"); - const glRoot = path.join(outputRoot, "gl"); - if (!fs.existsSync(glRoot)) { - fs.mkdirSync(glRoot, {recursive: true}); // Ensure target directory is available - } - fs.writeFileSync( path.join(glRoot, elem.header + ".hpp"), `${generatedHeader} @@ -257,8 +252,7 @@ JSON.parse(fs.readFileSync(path.join(shaderRoot, "manifest.json"))) namespace mbgl { namespace shaders { -template <> -struct ShaderSource { +template <> struct ShaderSource { static constexpr const char* name = "${elem.name}"; static constexpr const char* vertex = R"(${args.strip ? strip(vert) : vert})"; static constexpr const char* fragment = R"(${args.strip ? strip(frag) : frag})"; @@ -308,8 +302,7 @@ template struct ShaderSource; /// @brief A specialization of the ShaderSource template for no shader code. -template <> -struct ShaderSource { +template <> struct ShaderSource { static constexpr const char* name = ""; static constexpr const char* vertex = ""; static constexpr const char* fragment = ""; diff --git a/shaders/manifest.json b/shaders/manifest.json index 87b00a181..8cf11023c 100644 --- a/shaders/manifest.json +++ b/shaders/manifest.json @@ -1,4 +1,19 @@ [ + { + "name": "BackgroundShader", + "header": "drawable_background", + "glsl_vert": "drawable.background.vertex.glsl", + "glsl_frag": "drawable.background.fragment.glsl", + "uses_ubos": true + }, + { + "name": "FillShader", + "header": "drawable_fill", + "glsl_vert": "drawable.fill.vertex.glsl", + "glsl_frag": "drawable.fill.fragment.glsl", + "uses_ubos": true + }, + { "name": "Prelude", "header": "prelude", diff --git a/src/mbgl/gl/renderer_backend.cpp b/src/mbgl/gl/renderer_backend.cpp index 49fe20c13..372dbabfc 100644 --- a/src/mbgl/gl/renderer_backend.cpp +++ b/src/mbgl/gl/renderer_backend.cpp @@ -66,36 +66,35 @@ void RendererBackend::setScissorTest(bool enabled) { RendererBackend::~RendererBackend() = default; -void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) { - constexpr auto shaderName = "BackgroundProgramUBO"; +/// @brief Register a list of types with a shader registry instance +/// @tparam ...ShaderID Pack of BuiltIn:: shader IDs +/// @param registry A shader registry instance +/// @param glContext The GL context instance +/// @param programParameters ProgramParameters used to initialize each instance +template +void registerTypes(gfx::ShaderRegistry& registry, gl::Context& glContext, const ProgramParameters& programParameters) { + /// The following fold expression will create a shader for every type + /// in the parameter pack and register it with the shader registry. - gl::Context& glContext = static_cast(*context); - - auto shader = shaders.get(shaderName); - if (!shader) { - auto vert = shaders::ShaderSource::vertex; - auto frag = shaders::ShaderSource::fragment; - try { - // Compile - shader = gl::ShaderProgramGL::create(glContext, shaderName, vert, frag); - if (shader) { - // Set default values - // shader->setAttribute("a_color", gfx::VertexAttribute::matf4{ 1.0f, 1.0f, 1.0f, 1.0f }); - - // Add to the registry - if (!shaders.registerShader(shader, shaderName)) { - Log::Warning(Event::General, "Shader conflict - " + std::string(shaderName)); - return; - } - } else { - Log::Warning(Event::General, "Shader create failed - " + std::string(shaderName)); - return; + /// Registration calls are wrapped in a lambda that throws on registration + /// failure, we shouldn't expect registration to faill unless the shader + /// registry instance provided already has conflicting programs present. + ( + [&](const std::string& name, const std::string& vert, const std::string& frag) { + using Ty = shaders::ShaderSource; + if (!registry.registerShader(gl::ShaderProgramGL::create(glContext, programParameters, name, vert, frag), + name)) { + throw std::runtime_error("Failed to register " + std::string(Ty::name) + " with shader registry!"); } - } catch (const std::runtime_error& ex) { - Log::Warning(Event::General, "Shader create exception - " + std::string(ex.what())); - return; - } - } + }(shaders::ShaderSource::name, + shaders::ShaderSource::vertex, + shaders::ShaderSource::fragment), + ...); +} + +void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramParameters& programParameters) { + registerTypes( + shaders, static_cast(*context), programParameters); } } // namespace gl diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index de79cdb4e..0a26bac2b 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -197,8 +197,6 @@ void RenderBackgroundLayer::prepare(const LayerPrepareParameters& params) { } } -constexpr auto shaderName = "BackgroundProgramUBO"; - void RenderBackgroundLayer::layerRemoved(UniqueChangeRequestVec& changes) { // TODO: This isn't happening on style change, so old tile drawables are being left active @@ -221,7 +219,7 @@ void RenderBackgroundLayer::update(const int32_t layerIndex, std::unique_lock guard(mutex); if (!shader) { - shader = context.getGenericShader(shaders, shaderName); + shader = context.getGenericShader(shaders, "BackgroundDrawable"); } changes.emplace_back( diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index 1c01a6961..8c9dde772 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -261,8 +261,6 @@ bool RenderFillLayer::queryIntersectsFeature(const GeometryCoordinates& queryGeo feature.getGeometries()); } -constexpr auto shaderName = "BackgroundProgramUBO"; - void RenderFillLayer::layerRemoved(UniqueChangeRequestVec& changes) { // Remove everything decltype(tileDrawables) localDrawables; @@ -283,7 +281,7 @@ void RenderFillLayer::update(const int32_t layerIndex, std::unique_lock guard(mutex); if (!shader) { - shader = context.getGenericShader(shaders, shaderName); + shader = context.getGenericShader(shaders, "FillDrawable"); } // const auto& evaluated = getEvaluated(evaluatedProperties); diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 766729c8b..b84f24c4a 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -53,22 +53,25 @@ void Renderer::Impl::render(const RenderTree& renderTree) { observer->onWillStartRenderingFrame(); const auto& renderTreeParameters = renderTree.getParameters(); + auto& context = backend.getContext(); + // Blocks execution until the renderable is available. + backend.getDefaultRenderable().wait(); + if (!staticData) { staticData = std::make_unique(pixelRatio, std::make_unique()); + + // Initialize legacy shader programs staticData->programs.registerWith(*staticData->shaders); + + // Initialize shaders for drawables + const auto programParameters = ProgramParameters{pixelRatio, false}; + backend.initShaders(*staticData->shaders, programParameters); + + // Notify post-shader registration observer->onRegisterShaders(*staticData->shaders); } staticData->has3D = renderTreeParameters.has3D; - auto& context = backend.getContext(); - - // Now that the shader registry is set up, do one-time shader init. - // TODO: Both should be done earlier. - backend.initShaders(*staticData->shaders); - - // Blocks execution until the renderable is available. - backend.getDefaultRenderable().wait(); - PaintParameters parameters{context, pixelRatio, backend, diff --git a/src/mbgl/shaders/gl/shader_program_gl.cpp b/src/mbgl/shaders/gl/shader_program_gl.cpp index dd04a1212..412b9e9f7 100644 --- a/src/mbgl/shaders/gl/shader_program_gl.cpp +++ b/src/mbgl/shaders/gl/shader_program_gl.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -110,15 +112,29 @@ static void addAttr( } std::shared_ptr ShaderProgramGL::create(Context& context, - std::string_view /*name*/, - std::string_view vertexSource, - std::string_view fragmentSource) noexcept(false) { + const ProgramParameters& programParameters, + const std::string& /*name*/, + const std::string& vertexSource, + const std::string& fragmentSource, + const std::string& additionalDefines) noexcept(false) { const auto firstAttrib = "a_pos"; // throws on compile error - auto vertProg = context.createShader(ShaderType::Vertex, std::initializer_list{vertexSource.data()}); - auto fragProg = context.createShader(ShaderType::Fragment, - std::initializer_list{fragmentSource.data()}); + auto vertProg = context.createShader( + ShaderType::Vertex, + std::initializer_list{ + "#version 300 es\n", + programParameters.getDefines().c_str(), + additionalDefines.c_str(), + shaders::ShaderSource::vertex, + vertexSource.c_str()}); + auto fragProg = context.createShader( + ShaderType::Fragment, + {"#version 300 es\n", + programParameters.getDefines().c_str(), + additionalDefines.c_str(), + shaders::ShaderSource::fragment, + fragmentSource.c_str()}); auto program = context.createProgram(vertProg, fragProg, firstAttrib); // GLES3.1