Drawable Renderer (#1570), Setting up for fill patterns.
Handle color and cull modes better. Rename `DrawableBuilder::ColorMode` to `ColorAttrMode` to avoid confusion with `gfx::ColorMode`.
This commit is contained in:
committed by
Bart Louwers
parent
ec45ef654e
commit
b8bdf0643c
@@ -20,8 +20,8 @@ enum class RenderPass : uint8_t;
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class CullFaceMode;
|
||||
enum class DepthMaskType : bool;
|
||||
|
||||
class DrawableTweaker;
|
||||
class ShaderProgramBase;
|
||||
using ShaderProgramBasePtr = std::shared_ptr<ShaderProgramBase>;
|
||||
@@ -34,7 +34,7 @@ protected:
|
||||
Drawable(std::string name);
|
||||
|
||||
public:
|
||||
virtual ~Drawable() = default;
|
||||
virtual ~Drawable();
|
||||
|
||||
const util::SimpleIdentity& getId() const { return uniqueID; }
|
||||
|
||||
@@ -91,6 +91,9 @@ public:
|
||||
DepthMaskType getDepthType() const { return depthType; }
|
||||
void setDepthType(DepthMaskType value) { depthType = value; }
|
||||
|
||||
const gfx::CullFaceMode& getCullFaceMode() const;
|
||||
void setCullFaceMode(const gfx::CullFaceMode&);
|
||||
|
||||
/// Get the number of vertexes
|
||||
std::size_t getVertexCount() const { return getVertexAttributes().getMaxCount(); }
|
||||
|
||||
@@ -103,11 +106,11 @@ public:
|
||||
virtual std::vector<std::uint16_t>& getTriangleIndexData() const = 0;
|
||||
|
||||
/// Attach a tweaker to be run on this drawable for each frame
|
||||
void addTweaker(DrawableTweakerPtr tweaker) { tweakers.emplace_back(std::move(tweaker)); }
|
||||
template <typename TIter>
|
||||
void addTweakers(TIter beg, TIter end) {
|
||||
tweakers.insert(tweakers.end(), beg, end);
|
||||
}
|
||||
//void addTweaker(DrawableTweakerPtr tweaker) { tweakers.emplace_back(std::move(tweaker)); }
|
||||
//template <typename TIter>
|
||||
//void addTweakers(TIter beg, TIter end) {
|
||||
// tweakers.insert(tweakers.end(), beg, end);
|
||||
//}
|
||||
|
||||
/// Get the tweakers attached to this drawable
|
||||
const std::vector<DrawableTweakerPtr>& getTweakers() const { return tweakers; }
|
||||
@@ -140,7 +143,10 @@ protected:
|
||||
int32_t lineWidth = 1;
|
||||
int32_t layerIndex = -1;
|
||||
int32_t subLayerIndex = 0;
|
||||
DepthMaskType depthType; // = DepthMaskType::ReadOnly;
|
||||
DepthMaskType depthType;// = DepthMaskType::ReadOnly;
|
||||
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
|
||||
std::vector<DrawableTweakerPtr> tweakers;
|
||||
};
|
||||
|
||||
@@ -72,14 +72,15 @@ public:
|
||||
const Color& getColor() const;
|
||||
void setColor(const Color& value);
|
||||
|
||||
enum class ColorMode {
|
||||
/// Handling of color attributes
|
||||
enum class ColorAttrMode {
|
||||
None,
|
||||
PerDrawable,
|
||||
PerVertex
|
||||
};
|
||||
/// Set how the color value is used
|
||||
/// This should not be changed while a build is in progress
|
||||
void setColorMode(ColorMode mode) { colorMode = mode; }
|
||||
void setColorAttrMode(ColorAttrMode mode) { colorAttrMode = mode; }
|
||||
|
||||
/// Width for lines
|
||||
int32_t getLineWidth() const { return lineWidth; }
|
||||
@@ -88,6 +89,9 @@ public:
|
||||
DepthMaskType getDepthType() const { return depthType; }
|
||||
void setDepthType(DepthMaskType value) { depthType = value; }
|
||||
|
||||
const gfx::CullFaceMode& getCullFaceMode() const;
|
||||
void setCullFaceMode(const gfx::CullFaceMode& value);
|
||||
|
||||
/// Which shader to use when rendering emitted drawables
|
||||
const gfx::ShaderProgramBasePtr& getShader() const { return shader; }
|
||||
void setShader(gfx::ShaderProgramBasePtr value) { shader = std::move(value); }
|
||||
@@ -143,7 +147,7 @@ public:
|
||||
std::size_t indexLength);
|
||||
|
||||
/// Add a tweaker to be attached to each emitted drawable
|
||||
void addTweaker(DrawableTweakerPtr tweaker) { tweakers.emplace_back(std::move(tweaker)); }
|
||||
// void addTweaker(DrawableTweakerPtr tweaker) { tweakers.emplace_back(std::move(tweaker)); }
|
||||
|
||||
protected:
|
||||
/// Create an instance of the appropriate drawable type
|
||||
@@ -167,8 +171,7 @@ protected:
|
||||
mat4 matrix;
|
||||
UniqueDrawable currentDrawable;
|
||||
std::vector<UniqueDrawable> drawables;
|
||||
std::vector<DrawableTweakerPtr> tweakers;
|
||||
ColorMode colorMode = ColorMode::PerVertex;
|
||||
ColorAttrMode colorAttrMode = ColorAttrMode::PerVertex;
|
||||
VertexAttributeArray vertexAttrs;
|
||||
|
||||
struct Impl;
|
||||
|
||||
149
include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp
Normal file
149
include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp
Normal file
@@ -0,0 +1,149 @@
|
||||
// Generated code, do not modify this file!
|
||||
// Generated on 2023-05-23T18:10:10.798Z by timsylvester using shaders/generate_shader_code.js
|
||||
|
||||
#pragma once
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <> struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL> {
|
||||
static constexpr const char* name = "FillOutlinePatternShader";
|
||||
static constexpr const char* vertex = R"(uniform mat4 u_matrix;
|
||||
uniform vec2 u_world;
|
||||
uniform vec2 u_pixel_coord_upper;
|
||||
uniform vec2 u_pixel_coord_lower;
|
||||
uniform vec4 u_scale;
|
||||
|
||||
layout (location = 0) in vec2 a_pos;
|
||||
|
||||
out vec2 v_pos_a;
|
||||
out vec2 v_pos_b;
|
||||
out vec2 v_pos;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
uniform lowp float u_opacity_t;
|
||||
layout (location = 1) in lowp vec2 a_opacity;
|
||||
out lowp float opacity;
|
||||
#else
|
||||
uniform lowp float u_opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_from
|
||||
uniform lowp float u_pattern_from_t;
|
||||
layout (location = 2) in lowp vec4 a_pattern_from;
|
||||
out lowp vec4 pattern_from;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_from;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_to
|
||||
uniform lowp float u_pattern_to_t;
|
||||
layout (location = 3) in lowp vec4 a_pattern_to;
|
||||
out lowp vec4 pattern_to;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_to;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
|
||||
#else
|
||||
lowp float opacity = u_opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_from
|
||||
pattern_from = a_pattern_from;
|
||||
#else
|
||||
mediump vec4 pattern_from = u_pattern_from;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_to
|
||||
pattern_to = a_pattern_to;
|
||||
#else
|
||||
mediump vec4 pattern_to = u_pattern_to;
|
||||
#endif
|
||||
|
||||
vec2 pattern_tl_a = pattern_from.xy;
|
||||
vec2 pattern_br_a = pattern_from.zw;
|
||||
vec2 pattern_tl_b = pattern_to.xy;
|
||||
vec2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
float pixelRatio = u_scale.x;
|
||||
float tileRatio = u_scale.y;
|
||||
float fromScale = u_scale.z;
|
||||
float toScale = u_scale.w;
|
||||
|
||||
gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
||||
|
||||
vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
||||
vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
||||
|
||||
v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, fromScale * display_size_a, tileRatio, a_pos);
|
||||
v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileRatio, a_pos);
|
||||
|
||||
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world;
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(
|
||||
uniform vec2 u_texsize;
|
||||
uniform sampler2D u_image;
|
||||
uniform float u_fade;
|
||||
|
||||
in vec2 v_pos_a;
|
||||
in vec2 v_pos_b;
|
||||
in vec2 v_pos;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
in lowp float opacity;
|
||||
#else
|
||||
uniform lowp float u_opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_from
|
||||
in lowp vec4 pattern_from;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_from;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_to
|
||||
in lowp vec4 pattern_to;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_to;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifdef HAS_UNIFORM_u_opacity
|
||||
lowp float opacity = u_opacity;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_pattern_from
|
||||
mediump vec4 pattern_from = u_pattern_from;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_pattern_to
|
||||
mediump vec4 pattern_to = u_pattern_to;
|
||||
#endif
|
||||
|
||||
vec2 pattern_tl_a = pattern_from.xy;
|
||||
vec2 pattern_br_a = pattern_from.zw;
|
||||
vec2 pattern_tl_b = pattern_to.xy;
|
||||
vec2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
vec2 imagecoord = mod(v_pos_a, 1.0);
|
||||
vec2 pos = mix(pattern_tl_a / u_texsize, pattern_br_a / u_texsize, imagecoord);
|
||||
vec4 color1 = texture(u_image, pos);
|
||||
|
||||
vec2 imagecoord_b = mod(v_pos_b, 1.0);
|
||||
vec2 pos2 = mix(pattern_tl_b / u_texsize, pattern_br_b / u_texsize, imagecoord_b);
|
||||
vec4 color2 = texture(u_image, pos2);
|
||||
|
||||
// find distance to outline for alpha interpolation
|
||||
|
||||
float dist = length(v_pos - gl_FragCoord.xy);
|
||||
float alpha = 1.0 - smoothstep(0.0, 1.0, dist);
|
||||
|
||||
|
||||
fragColor = mix(color1, color2, u_fade) * alpha * opacity;
|
||||
|
||||
#ifdef OVERDRAW_INSPECTOR
|
||||
fragColor = vec4(1.0);
|
||||
#endif
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
137
include/mbgl/shaders/gl/drawable_fill_pattern.hpp
Normal file
137
include/mbgl/shaders/gl/drawable_fill_pattern.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
// Generated code, do not modify this file!
|
||||
// Generated on 2023-05-23T18:10:10.798Z by timsylvester using shaders/generate_shader_code.js
|
||||
|
||||
#pragma once
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <> struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL> {
|
||||
static constexpr const char* name = "FillPatternShader";
|
||||
static constexpr const char* vertex = R"(uniform mat4 u_matrix;
|
||||
uniform vec2 u_pixel_coord_upper;
|
||||
uniform vec2 u_pixel_coord_lower;
|
||||
uniform vec4 u_scale;
|
||||
|
||||
layout (location = 0) in vec2 a_pos;
|
||||
|
||||
out vec2 v_pos_a;
|
||||
out vec2 v_pos_b;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
uniform lowp float u_opacity_t;
|
||||
layout (location = 1) in lowp vec2 a_opacity;
|
||||
out lowp float opacity;
|
||||
#else
|
||||
uniform lowp float u_opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_from
|
||||
uniform lowp float u_pattern_from_t;
|
||||
layout (location = 2) in lowp vec4 a_pattern_from;
|
||||
out lowp vec4 pattern_from;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_from;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_to
|
||||
uniform lowp float u_pattern_to_t;
|
||||
layout (location = 3) in lowp vec4 a_pattern_to;
|
||||
out lowp vec4 pattern_to;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_to;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
|
||||
#else
|
||||
lowp float opacity = u_opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_from
|
||||
pattern_from = a_pattern_from;
|
||||
#else
|
||||
mediump vec4 pattern_from = u_pattern_from;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_to
|
||||
pattern_to = a_pattern_to;
|
||||
#else
|
||||
mediump vec4 pattern_to = u_pattern_to;
|
||||
#endif
|
||||
|
||||
vec2 pattern_tl_a = pattern_from.xy;
|
||||
vec2 pattern_br_a = pattern_from.zw;
|
||||
vec2 pattern_tl_b = pattern_to.xy;
|
||||
vec2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
float pixelRatio = u_scale.x;
|
||||
float tileZoomRatio = u_scale.y;
|
||||
float fromScale = u_scale.z;
|
||||
float toScale = u_scale.w;
|
||||
|
||||
vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
||||
vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
||||
gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
||||
|
||||
v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, a_pos);
|
||||
v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileZoomRatio, a_pos);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(uniform vec2 u_texsize;
|
||||
uniform float u_fade;
|
||||
|
||||
uniform sampler2D u_image;
|
||||
|
||||
in vec2 v_pos_a;
|
||||
in vec2 v_pos_b;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
in lowp float opacity;
|
||||
#else
|
||||
uniform lowp float u_opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_from
|
||||
in lowp vec4 pattern_from;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_from;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_pattern_to
|
||||
in lowp vec4 pattern_to;
|
||||
#else
|
||||
uniform lowp vec4 u_pattern_to;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifdef HAS_UNIFORM_u_opacity
|
||||
lowp float opacity = u_opacity;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_pattern_from
|
||||
mediump vec4 pattern_from = u_pattern_from;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_pattern_to
|
||||
mediump vec4 pattern_to = u_pattern_to;
|
||||
#endif
|
||||
|
||||
vec2 pattern_tl_a = pattern_from.xy;
|
||||
vec2 pattern_br_a = pattern_from.zw;
|
||||
vec2 pattern_tl_b = pattern_to.xy;
|
||||
vec2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
vec2 imagecoord = mod(v_pos_a, 1.0);
|
||||
vec2 pos = mix(pattern_tl_a / u_texsize, pattern_br_a / u_texsize, imagecoord);
|
||||
vec4 color1 = texture(u_image, pos);
|
||||
|
||||
vec2 imagecoord_b = mod(v_pos_b, 1.0);
|
||||
vec2 pos2 = mix(pattern_tl_b / u_texsize, pattern_br_b / u_texsize, imagecoord_b);
|
||||
vec4 color2 = texture(u_image, pos2);
|
||||
|
||||
fragColor = mix(color1, color2, u_fade) * opacity;
|
||||
|
||||
#ifdef OVERDRAW_INSPECTOR
|
||||
fragColor = vec4(1.0);
|
||||
#endif
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -1,5 +1,5 @@
|
||||
// Generated code, do not modify this file!
|
||||
// Generated on 2023-05-12T17:51:34.322Z by mwilsnd using shaders/generate_shader_code.js
|
||||
// Generated on 2023-05-23T18:10:10.798Z by timsylvester using shaders/generate_shader_code.js
|
||||
|
||||
#pragma once
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <mbgl/shaders/gl/drawable_background.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_fill.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_fill_outline.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_fill_pattern.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_fill_outline_pattern.hpp>
|
||||
#include <mbgl/shaders/gl/prelude.hpp>
|
||||
#include <mbgl/shaders/gl/background.hpp>
|
||||
#include <mbgl/shaders/gl/background_pattern.hpp>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Generated code, do not modify this file!
|
||||
// Generated on 2023-05-12T17:51:34.322Z by mwilsnd using shaders/generate_shader_code.js
|
||||
// Generated on 2023-05-23T18:10:10.798Z by timsylvester using shaders/generate_shader_code.js
|
||||
|
||||
#pragma once
|
||||
#include <mbgl/gfx/backend.hpp>
|
||||
@@ -14,6 +14,8 @@ enum class BuiltIn {
|
||||
BackgroundShader,
|
||||
FillShader,
|
||||
FillOutlineShader,
|
||||
FillPatternShader,
|
||||
FillOutlinePatternShader,
|
||||
Prelude,
|
||||
BackgroundProgram,
|
||||
BackgroundPatternProgram,
|
||||
|
||||
Reference in New Issue
Block a user