Drawable Renderer (#1570), [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2023-05-02 16:50:53 +00:00
committed by Bart Louwers
parent b2a3e518c7
commit caee9cc12f
43 changed files with 454 additions and 417 deletions

View File

@@ -31,7 +31,6 @@ using UniqueDrawableBuilder = std::unique_ptr<DrawableBuilder>;
using DrawableTweakerPtr = std::shared_ptr<DrawableTweaker>;
using ShaderProgramBasePtr = std::shared_ptr<ShaderProgramBase>;
class Context {
protected:
Context(uint32_t maximumVertexBindingCount_)
@@ -96,18 +95,17 @@ public:
#endif
virtual void clearStencilBuffer(int32_t) = 0;
public:
/// Activate the shader, vertex attributes, etc., specified by the drawable
virtual bool setupDraw(const PaintParameters&, const gfx::Drawable&) = 0;
/// Create a new drawable builder
virtual UniqueDrawableBuilder createDrawableBuilder(std::string name) = 0;
/// Create a new drawable tweaker
virtual DrawableTweakerPtr createDrawableTweaker() = 0;
/// Get the generic shader with the specified name
virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0;
};

View File

@@ -5,13 +5,10 @@
namespace mbgl {
namespace gfx {
Drawable::Drawable(std::string name_) :
name(name_),
matrix(matrix::identity4()),
depthType(DepthMaskType::ReadOnly)
{
}
Drawable::Drawable(std::string name_)
: name(name_),
matrix(matrix::identity4()),
depthType(DepthMaskType::ReadOnly) {}
} // namespace gfx
} // namespace mbgl

View File

@@ -4,10 +4,9 @@
namespace mbgl {
namespace gfx {
DrawableBuilder::DrawableBuilder(std::string name_) :
name(std::move(name_)),
impl(std::make_unique<Impl>()) {
}
DrawableBuilder::DrawableBuilder(std::string name_)
: name(std::move(name_)),
impl(std::make_unique<Impl>()) {}
DrawableBuilder::~DrawableBuilder() = default;
@@ -59,17 +58,17 @@ void DrawableBuilder::setDrawPriority(DrawPriority value) {
void DrawableBuilder::resetDrawPriority(DrawPriority value) {
setDrawPriority(value);
for (auto &drawble : drawables) {
for (auto& drawble : drawables) {
drawble->setDrawPriority(value);
}
}
void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
const auto n = (uint16_t)impl->vertices.elements();
impl->vertices.emplace_back(Impl::VT({{{ x0, y0 }}}));
impl->vertices.emplace_back(Impl::VT({{{ x1, y1 }}}));
impl->vertices.emplace_back(Impl::VT({{{ x2, y2 }}}));
impl->indexes.emplace_back(n, n+1, n+2);
impl->vertices.emplace_back(Impl::VT({{{x0, y0}}}));
impl->vertices.emplace_back(Impl::VT({{{x1, y1}}}));
impl->vertices.emplace_back(Impl::VT({{{x2, y2}}}));
impl->indexes.emplace_back(n, n + 1, n + 2);
if (colorMode == ColorMode::PerVertex) {
impl->colors.insert(impl->colors.end(), 3, impl->currentColor);
}
@@ -77,8 +76,8 @@ void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1
void DrawableBuilder::appendTriangle(int16_t x0, int16_t y0) {
const auto n = (uint16_t)impl->vertices.elements();
impl->vertices.emplace_back(Impl::VT({{{ x0, y0 }}}));
impl->indexes.emplace_back(n-2, n-1, n);
impl->vertices.emplace_back(Impl::VT({{{x0, y0}}}));
impl->indexes.emplace_back(n - 2, n - 1, n);
if (colorMode == ColorMode::PerVertex) {
impl->colors.emplace_back(impl->currentColor);
}

View File

@@ -10,7 +10,7 @@ namespace mbgl {
namespace gfx {
struct DrawableBuilder::Impl {
using VT = gfx::detail::VertexType<gfx::AttributeType<std::int16_t,2>>;
using VT = gfx::detail::VertexType<gfx::AttributeType<std::int16_t, 2>>;
gfx::VertexVector<VT> vertices;
gfx::IndexVector<gfx::Triangles> indexes;
SegmentVector<TypeList<void>> segments;
@@ -20,4 +20,3 @@ struct DrawableBuilder::Impl {
} // namespace gfx
} // namespace mbgl

View File

@@ -8,21 +8,19 @@ namespace mbgl {
namespace gfx {
VertexAttributeArray::VertexAttributeArray(int initCapacity)
: attrs(initCapacity) {
}
: attrs(initCapacity) {}
VertexAttributeArray::VertexAttributeArray(VertexAttributeArray &&other)
: attrs(std::move(other.attrs)) {
}
VertexAttributeArray::VertexAttributeArray(VertexAttributeArray&& other)
: attrs(std::move(other.attrs)) {}
VertexAttributeArray& VertexAttributeArray::operator=(VertexAttributeArray &&other) {
VertexAttributeArray& VertexAttributeArray::operator=(VertexAttributeArray&& other) {
attrs = std::move(other.attrs);
return *this;
}
VertexAttributeArray& VertexAttributeArray::operator=(const VertexAttributeArray& other) {
attrs.clear();
for (const auto &kv : other.attrs) {
for (const auto& kv : other.attrs) {
add(kv.first, copy(*kv.second));
}
return *this;
@@ -33,8 +31,8 @@ VertexAttribute* VertexAttributeArray::get(const std::string& name) const {
return (result != attrs.end()) ? result->second.get() : nullptr;
}
VertexAttribute* VertexAttributeArray::add(std::string name, int index,
AttributeDataType dataType, int size, std::size_t count) {
VertexAttribute* VertexAttributeArray::add(
std::string name, int index, AttributeDataType dataType, int size, std::size_t count) {
const auto result = attrs.insert(std::make_pair(std::move(name), std::unique_ptr<VertexAttribute>()));
if (result.second) {
result.first->second = create(index, dataType, size, count);
@@ -44,15 +42,14 @@ VertexAttribute* VertexAttributeArray::add(std::string name, int index,
}
}
VertexAttribute* VertexAttributeArray::getOrAdd(std::string name, int index,
AttributeDataType dataType, int size, std::size_t count) {
//attrs.emplace_back(std::make_unique<VertexAttribute>(dataType, count));
VertexAttribute* VertexAttributeArray::getOrAdd(
std::string name, int index, AttributeDataType dataType, int size, std::size_t count) {
// attrs.emplace_back(std::make_unique<VertexAttribute>(dataType, count));
const auto result = attrs.insert(std::make_pair(std::move(name), std::unique_ptr<VertexAttribute>()));
if (result.second) {
result.first->second = create(index, dataType, size, count);
} else if (result.first->second->getDataType() != dataType ||
result.first->second->getSize() != (std::size_t)size ||
result.first->second->getCount() != count) {
result.first->second->getSize() != (std::size_t)size || result.first->second->getCount() != count) {
return nullptr;
}
return result.first->second.get();
@@ -65,14 +62,12 @@ std::size_t VertexAttributeArray::getTotalSize() const {
}
std::size_t VertexAttributeArray::getMaxCount() const {
return std::accumulate(attrs.begin(), attrs.end(), std::size_t(0),
[](const auto acc, const auto& kv) {
return std::max(acc, kv.second->getCount());
});
return std::accumulate(attrs.begin(), attrs.end(), std::size_t(0), [](const auto acc, const auto& kv) {
return std::max(acc, kv.second->getCount());
});
}
void VertexAttributeArray::resolve(const VertexAttributeArray& overrides,
ResolveDelegate delegate) const {
void VertexAttributeArray::resolve(const VertexAttributeArray& overrides, ResolveDelegate delegate) const {
for (auto& kv : attrs) {
delegate(kv.first, *kv.second, overrides.get(kv.first));
}

View File

@@ -453,7 +453,7 @@ void Context::setDirtyState() {
}
bool Context::setupDraw(const PaintParameters& parameters, const gfx::Drawable& drawable) {
if (const auto &shader = drawable.getShader()) {
if (const auto& shader = drawable.getShader()) {
const auto& shaderGL = static_cast<const ShaderProgramGL&>(*shader);
if (shaderGL.getGLProgramID() != program.getCurrentValue()) {
program = shaderGL.getGLProgramID();
@@ -473,7 +473,7 @@ bool Context::setupDraw(const PaintParameters& parameters, const gfx::Drawable&
auto& drawableGL = static_cast<const DrawableGL&>(drawable);
auto& vao = drawableGL.getVertexArray();
if (vao.isValid()) {
bindVertexArray = vao.getID(); // glBindVertexArray
bindVertexArray = vao.getID(); // glBindVertexArray
return true;
} else {
bindVertexArray = value::BindVertexArray::Default;

View File

@@ -5,19 +5,17 @@
namespace mbgl {
namespace gl {
DrawableGL::DrawableGL(std::string name_) :
Drawable(std::move(name_)),
impl(std::make_unique<Impl>()) {
}
DrawableGL::DrawableGL(std::string name_)
: Drawable(std::move(name_)),
impl(std::make_unique<Impl>()) {}
DrawableGL::~DrawableGL() {
impl->vertexArray = { { nullptr, false } };
impl->indexBuffer = { 0, nullptr };
impl->vertexArray = {{nullptr, false}};
impl->indexBuffer = {0, nullptr};
impl->attributeBuffer.reset();
}
void DrawableGL::draw(const PaintParameters &parameters) const
{
void DrawableGL::draw(const PaintParameters& parameters) const {
impl->draw(parameters);
}

View File

@@ -50,4 +50,3 @@ void DrawableGLBuilder::init() {
} // namespace gl
} // namespace mbgl

View File

@@ -22,7 +22,6 @@ namespace gl {
using namespace platform;
class DrawableGL::Impl final {
public:
Impl() = default;
~Impl() = default;
@@ -33,19 +32,19 @@ public:
}
const gfx::Triangles drawMode;
//const gfx::DrawModeType type = gfx::DrawModeType::Triangles;
// const gfx::DrawModeType type = gfx::DrawModeType::Triangles;
//ShaderID shaderId;
//RenderbufferID renderTarget;
// ShaderID shaderId;
// RenderbufferID renderTarget;
std::vector<TextureID> textures;
//std::vector<std::uint8_t> vertData;
// std::vector<std::uint8_t> vertData;
std::vector<std::uint16_t> indexes;
VertexAttributeArrayGL vertexAttributes;
VertexArray vertexArray = { { nullptr, false } };
gfx::IndexBuffer indexBuffer = { 0, nullptr };
VertexArray vertexArray = {{nullptr, false}};
gfx::IndexBuffer indexBuffer = {0, nullptr};
gfx::UniqueVertexBufferResource attributeBuffer;
std::size_t indexOffset = 0;
@@ -55,10 +54,10 @@ public:
gfx::StencilMode stencilMode;
gfx::ColorMode colorMode;
gfx::CullFaceMode cullFaceMode;
//gfx::UniformValues<typename Program<>::UniformList> uniformValues;
//Segment<Program<>::AttributeList> segment;
//gfx::AttributeBindings<Program<>::AttributeList> attributeBindings;
//gfx::TextureBindings<Program<>::TextureList> textureBindings;
// gfx::UniformValues<typename Program<>::UniformList> uniformValues;
// Segment<Program<>::AttributeList> segment;
// gfx::AttributeBindings<Program<>::AttributeList> attributeBindings;
// gfx::TextureBindings<Program<>::TextureList> textureBindings;
GLfloat pointSize = 0.0f;
};

View File

@@ -5,7 +5,7 @@
namespace mbgl {
namespace gl {
void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters &) {
void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters&) {
auto& drawGL = (gl::DrawableGL&)drawable;
// apply expressions based on current state, update attributes, uniforms, etc.
drawGL.getId();
@@ -13,4 +13,3 @@ void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters &
} // namespace gl
} // namespace mbgl

View File

@@ -98,7 +98,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) {
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 });
// shader->setAttribute("a_color", gfx::VertexAttribute::matf4{ 1.0f, 1.0f, 1.0f, 1.0f });
// Add to the registry
if (!shaders.registerShader(shader, shaderName)) {
@@ -109,7 +109,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) {
Log::Warning(Event::General, "Shader create failed - " + std::string(shaderName));
return;
}
} catch (const std::runtime_error& ex) {
} catch (const std::runtime_error& ex) {
Log::Warning(Event::General, "Shader create exception - " + std::string(ex.what()));
return;
}

View File

@@ -132,12 +132,11 @@ static void pad(std::vector<T>& vector, std::size_t size, T value) {
}
gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
const std::size_t vertexCount,
const gfx::VertexAttributeArray& defaults,
const gfx::VertexAttributeArray& overrides,
const gfx::BufferUsageType usage,
/*out*/ std::unique_ptr<gfx::VertexBufferResource>& outBuffer) {
const std::size_t vertexCount,
const gfx::VertexAttributeArray& defaults,
const gfx::VertexAttributeArray& overrides,
const gfx::BufferUsageType usage,
/*out*/ std::unique_ptr<gfx::VertexBufferResource>& outBuffer) {
AttributeBindingArray bindings;
bindings.resize(defaults.size());
@@ -148,55 +147,55 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
allData.reserve(defaults.getTotalSize() * vertexCount);
// For each attribute in the program, with the corresponding default and optional override...
defaults.resolve(overrides, [&](const std::string& name,
const gfx::VertexAttribute& defaultAttr,
const gfx::VertexAttribute* overrideAttr)->void {
defaults.resolve(overrides,
[&](const std::string& name,
const gfx::VertexAttribute& defaultAttr,
const gfx::VertexAttribute* overrideAttr) -> void {
const auto& effectiveAttr = overrideAttr ? *overrideAttr : defaultAttr;
const auto& effectiveGL = static_cast<const gl::VertexAttributeGL&>(effectiveAttr);
const auto& defaultGL = static_cast<const gl::VertexAttributeGL&>(defaultAttr);
const auto stride = defaultAttr.getStride();
const auto offset = static_cast<uint8_t>(allData.size());
const auto& effectiveAttr = overrideAttr ? *overrideAttr : defaultAttr;
const auto& effectiveGL = static_cast<const gl::VertexAttributeGL&>(effectiveAttr);
const auto& defaultGL = static_cast<const gl::VertexAttributeGL&>(defaultAttr);
const auto stride = defaultAttr.getStride();
const auto offset = static_cast<uint8_t>(allData.size());
// Get the raw data for the values in the desired format
const auto& rawData = effectiveGL.getRaw(defaultGL.getGLType());
// Get the raw data for the values in the desired format
const auto& rawData = effectiveGL.getRaw(defaultGL.getGLType());
if (rawData.size() == stride * vertexCount) {
// The override provided a value for each vertex, append it as-is
allData.insert(allData.end(), rawData.begin(), rawData.end());
} else if (rawData.size() == stride) {
// We only have one value, append a copy for each vertex
for (std::size_t i = 0; i < vertexCount; ++i) {
allData.insert(allData.end(), rawData.begin(), rawData.end());
}
} else {
// something else, the binding is invalid
// TODO: throw?
Log::Warning(Event::General,
"Got " + util::toString(rawData.size()) + " bytes for attribute '" + name +
"' (" + util::toString(defaultGL.getIndex()) + "), expected " +
util::toString(stride) + " or " + util::toString(stride * vertexCount));
return;
}
if (rawData.size() == stride * vertexCount) {
// The override provided a value for each vertex, append it as-is
allData.insert(allData.end(), rawData.begin(), rawData.end());
} else if (rawData.size() == stride) {
// We only have one value, append a copy for each vertex
for (std::size_t i = 0; i < vertexCount; ++i) {
allData.insert(allData.end(), rawData.begin(), rawData.end());
}
} else {
// something else, the binding is invalid
// TODO: throw?
Log::Warning(Event::General,
"Got " + util::toString(rawData.size()) + " bytes for attribute '" + name +
"' (" + util::toString(defaultGL.getIndex()) + "), expected " +
util::toString(stride) + " or " + util::toString(stride * vertexCount));
return;
}
bindings[defaultGL.getIndex()] = {
/*.attribute = */ {defaultAttr.getDataType(), offset},
/*.vertexStride = */ static_cast<uint8_t>(stride),
/*.vertexBufferResource = */ nullptr, // buffer pointer established later
/*.vertexOffset = */ 0,
};
bindings[defaultGL.getIndex()] = {
/*.attribute = */ { defaultAttr.getDataType(), offset },
/*.vertexStride = */ static_cast<uint8_t>(stride),
/*.vertexBufferResource = */nullptr, // buffer pointer established later
/*.vertexOffset = */ 0,
};
pad(allData, align, padding);
});
pad(allData, align, padding);
});
auto vertBuf = createVertexBufferResource(allData.data(), allData.size(), usage);
// Go back and fill in the newly-allocated buffer in each binding that was generated
std::for_each(bindings.begin(), bindings.end(), [&](auto& b) {
if (b) {
b->vertexBufferResource = vertBuf.get();
}
});
if (b) {
b->vertexBufferResource = vertBuf.get();
}
});
outBuffer = std::move(vertBuf);
return bindings;

View File

@@ -17,33 +17,55 @@ using namespace platform;
int VertexAttributeGL::getSize(GLenum glType) {
switch (glType) {
case GL_FLOAT: return 4*1;
case GL_FLOAT_VEC2: return 4*2;
case GL_FLOAT_VEC3: return 4*3;
case GL_FLOAT_VEC4: return 4*4;
case GL_FLOAT_MAT2: return 4*4;
case GL_INT: return 4*1;
case GL_UNSIGNED_INT: return 4*1;
case GL_INT_VEC2: return 4*2;
case GL_INT_VEC3: return 4*3;
case GL_INT_VEC4: return 4*4;
default: return 0;
case GL_FLOAT:
return 4 * 1;
case GL_FLOAT_VEC2:
return 4 * 2;
case GL_FLOAT_VEC3:
return 4 * 3;
case GL_FLOAT_VEC4:
return 4 * 4;
case GL_FLOAT_MAT2:
return 4 * 4;
case GL_INT:
return 4 * 1;
case GL_UNSIGNED_INT:
return 4 * 1;
case GL_INT_VEC2:
return 4 * 2;
case GL_INT_VEC3:
return 4 * 3;
case GL_INT_VEC4:
return 4 * 4;
default:
return 0;
}
}
int VertexAttributeGL::getStride(GLenum glType) {
switch (glType) {
case GL_FLOAT: return 4*1;
case GL_FLOAT_VEC2: return 4*2;
case GL_FLOAT_VEC3: return 4*4;
case GL_FLOAT_VEC4: return 4*4;
case GL_FLOAT_MAT2: return 4*4;
case GL_INT: return 4*1;
case GL_UNSIGNED_INT: return 4*1;
case GL_INT_VEC2: return 4*2;
case GL_INT_VEC3: return 4*4;
case GL_INT_VEC4: return 4*4;
default: return 0;
case GL_FLOAT:
return 4 * 1;
case GL_FLOAT_VEC2:
return 4 * 2;
case GL_FLOAT_VEC3:
return 4 * 4;
case GL_FLOAT_VEC4:
return 4 * 4;
case GL_FLOAT_MAT2:
return 4 * 4;
case GL_INT:
return 4 * 1;
case GL_UNSIGNED_INT:
return 4 * 1;
case GL_INT_VEC2:
return 4 * 2;
case GL_INT_VEC3:
return 4 * 4;
case GL_INT_VEC4:
return 4 * 4;
default:
return 0;
}
}
@@ -60,40 +82,56 @@ static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffe
// Copy the value into the buffer with a simple cast, returning true if it works.
template <typename T, typename R>
static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
return get<T,R>(element, buffer, [](T x)->R{ return static_cast<R>(x); });
return get<T, R>(element, buffer, [](T x) -> R { return static_cast<R>(x); });
}
// Copy a particular type from the variant into the specified buffer, returning true if it works.
template <typename T>
static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
return get<T,T>(element, buffer, [](T x)->T{ return x; });
return get<T, T>(element, buffer, [](T x) -> T { return x; });
}
template <typename T, typename R> R cast(T x) { return static_cast<R>(x); }
template <typename T, typename R>
R cast(T x) {
return static_cast<R>(x);
}
// Copy the variant value into the buffer, converting the type if necessary and possible
bool VertexAttributeGL::get(const gfx::VertexAttribute::ElementType& element, GLenum glType, uint8_t* buffer) {
// TODO: do we need to handle unsigned inputs?
switch (glType) {
case GL_FLOAT: return gl::get<float>(element, buffer) ||
gl::get<float,std::int32_t>(element, buffer);
case GL_FLOAT_VEC2: return gl::get<float2>(element, buffer) ||
gl::get<int2,float2>(element, buffer, [](int2 x){ return float2{(float)x[0],(float)x[1]}; });
case GL_FLOAT_VEC3: return gl::get<float3>(element, buffer);
case GL_FLOAT:
return gl::get<float>(element, buffer) || gl::get<float, std::int32_t>(element, buffer);
case GL_FLOAT_VEC2:
return gl::get<float2>(element, buffer) || gl::get<int2, float2>(element, buffer, [](int2 x) {
return float2{(float)x[0], (float)x[1]};
});
case GL_FLOAT_VEC3:
return gl::get<float3>(element, buffer);
case GL_FLOAT_VEC4:
case GL_FLOAT_MAT2: return gl::get<float4>(element, buffer);
case GL_INT: return gl::get<std::int32_t>(element, buffer) ||
gl::get<float, std::int32_t> (element, buffer);
case GL_UNSIGNED_INT: return gl::get<std::int32_t,std::uint32_t>(element, buffer) ||
gl::get<float, std::uint32_t>(element, buffer);
case GL_INT_VEC2: return gl::get<int2>(element, buffer) ||
gl::get<float2,int2>(element, buffer, [](float2 x){ return int2{(std::int32_t)x[0],(std::int32_t)x[1]}; });
case GL_UNSIGNED_INT_VEC2: return false; // TODO
case GL_INT_VEC3: return gl::get<int3>(element, buffer);
case GL_UNSIGNED_INT_VEC3: return false; // TODO
case GL_INT_VEC4: return gl::get<int4>(element, buffer);
case GL_UNSIGNED_INT_VEC4: return false; // TODO
default: return false;
case GL_FLOAT_MAT2:
return gl::get<float4>(element, buffer);
case GL_INT:
return gl::get<std::int32_t>(element, buffer) || gl::get<float, std::int32_t>(element, buffer);
case GL_UNSIGNED_INT:
return gl::get<std::int32_t, std::uint32_t>(element, buffer) ||
gl::get<float, std::uint32_t>(element, buffer);
case GL_INT_VEC2:
return gl::get<int2>(element, buffer) || gl::get<float2, int2>(element, buffer, [](float2 x) {
return int2{(std::int32_t)x[0], (std::int32_t)x[1]};
});
case GL_UNSIGNED_INT_VEC2:
return false; // TODO
case GL_INT_VEC3:
return gl::get<int3>(element, buffer);
case GL_UNSIGNED_INT_VEC3:
return false; // TODO
case GL_INT_VEC4:
return gl::get<int4>(element, buffer);
case GL_UNSIGNED_INT_VEC4:
return false; // TODO
default:
return false;
}
}
@@ -109,7 +147,7 @@ std::size_t VertexAttributeGL::getStride() const {
const std::vector<std::uint8_t>& VertexAttributeGL::getRaw(platform::GLenum type) const {
if (dirty || rawType != type) {
const auto count = getCount();
//const auto size_ = getSize(type);
// const auto size_ = getSize(type);
const auto stride_ = getStride(type);
rawData.resize(stride_ * count);
@@ -132,24 +170,38 @@ const std::vector<std::uint8_t>& VertexAttributeGL::getRaw(platform::GLenum type
}
namespace {
template <typename T> void applyUniform(GLint, const T&);
template <> void applyUniform(GLint, const std::int32_t&) { }
template <> void applyUniform(GLint, const gfx::VertexAttribute::int2&) { }
template <> void applyUniform(GLint, const gfx::VertexAttribute::int3&) { }
template <> void applyUniform(GLint, const gfx::VertexAttribute::int4&) { }
template <> void applyUniform(GLint, const float& ) { }
template <> void applyUniform(GLint, const gfx::VertexAttribute::float2& ) { }
template <> void applyUniform(GLint, const gfx::VertexAttribute::float3& ) { }
template <> void applyUniform(GLint, const gfx::VertexAttribute::float4& ) { }
template <> void applyUniform(GLint, const gfx::VertexAttribute::matf3& ) { }
template <> void applyUniform(GLint location, const gfx::VertexAttribute::matf4& value) {
MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, value.data()));
}
template <typename T>
void applyUniform(GLint, const T&);
template <>
void applyUniform(GLint, const std::int32_t&) {}
template <>
void applyUniform(GLint, const gfx::VertexAttribute::int2&) {}
template <>
void applyUniform(GLint, const gfx::VertexAttribute::int3&) {}
template <>
void applyUniform(GLint, const gfx::VertexAttribute::int4&) {}
template <>
void applyUniform(GLint, const float&) {}
template <>
void applyUniform(GLint, const gfx::VertexAttribute::float2&) {}
template <>
void applyUniform(GLint, const gfx::VertexAttribute::float3&) {}
template <>
void applyUniform(GLint, const gfx::VertexAttribute::float4&) {}
template <>
void applyUniform(GLint, const gfx::VertexAttribute::matf3&) {}
template <>
void applyUniform(GLint location, const gfx::VertexAttribute::matf4& value) {
MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, value.data()));
}
} // namespace
struct ApplyUniform {
GLint location;
template <typename T> void operator()(const T& value) { applyUniform(location, value); }
template <typename T>
void operator()(const T& value) {
applyUniform(location, value);
}
};
void VertexAttributeArrayGL::applyUniforms(const gfx::ShaderProgramBase& shader) {
@@ -165,10 +217,9 @@ void VertexAttributeArrayGL::applyUniforms(const gfx::ShaderProgramBase& shader)
Log::Warning(Event::General, "Uniform '" + name + "' = " + std::to_string(index));
uniform->setIndex(index);
}
std::visit(ApplyUniform { uniform->getIndex() }, uniform->get(0));
std::visit(ApplyUniform{uniform->getIndex()}, uniform->get(0));
}
}
} // namespace gfx
} // namespace gl
} // namespace mbgl

View File

@@ -12,7 +12,7 @@ void RemoveDrawableRequest::execute(RenderOrchestrator &orchestrator) {
}
void ResetColorRequest::execute(RenderOrchestrator &orchestrator) {
if (auto& drawable = orchestrator.getDrawable(drawableID)) {
if (auto &drawable = orchestrator.getDrawable(drawableID)) {
drawable->resetColor(newColor);
}
}

View File

@@ -165,7 +165,7 @@ std::optional<Color> RenderBackgroundLayer::getSolidBackground() const {
}
return std::nullopt;
//return { evaluated.get<BackgroundColor>() * evaluated.get<BackgroundOpacity>() };
// return { evaluated.get<BackgroundColor>() * evaluated.get<BackgroundOpacity>() };
}
namespace {

View File

@@ -12,9 +12,9 @@
namespace mbgl {
namespace gfx {
class Drawable;
using DrawablePtr = std::shared_ptr<Drawable>;
} // namespace gfc
class Drawable;
using DrawablePtr = std::shared_ptr<Drawable>;
} // namespace gfx
class ChangeRequest;

View File

@@ -138,7 +138,6 @@ void RenderOrchestrator::setObserver(RendererObserver* observer_) {
std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
const std::shared_ptr<UpdateParameters>& updateParameters) {
layersAdded.clear();
layersRemoved.clear();
@@ -723,8 +722,8 @@ bool RenderOrchestrator::isLoaded() const {
if (!imageManager->isLoaded()) {
return false;
}
for (const auto& entry: renderSources) {
for (const auto& entry : renderSources) {
if (!entry.second->isLoaded()) {
return false;
}
@@ -751,9 +750,8 @@ void RenderOrchestrator::clearData() {
}
void RenderOrchestrator::addChanges(UniqueChangeRequestVec& changes) {
pendingChanges.insert(pendingChanges.end(),
std::make_move_iterator(changes.begin()),
std::make_move_iterator(changes.end()));
pendingChanges.insert(
pendingChanges.end(), std::make_move_iterator(changes.begin()), std::make_move_iterator(changes.end()));
changes.clear();
}
@@ -780,25 +778,25 @@ void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders,
gfx::Context& context,
const TransformState& state,
const std::shared_ptr<UpdateParameters>& updateParameters) {
const bool isMapModeContinuous = updateParameters->mode == MapMode::Continuous;
const auto transitionOptions = isMapModeContinuous ? updateParameters->transitionOptions : style::TransitionOptions();
const auto transitionOptions = isMapModeContinuous ? updateParameters->transitionOptions
: style::TransitionOptions();
const auto defDuration = isMapModeContinuous ? util::DEFAULT_TRANSITION_DURATION : Duration::zero();
const PropertyEvaluationParameters evalParameters {
const PropertyEvaluationParameters evalParameters{
getZoomHistory(),
updateParameters->timePoint,
transitionOptions.duration.value_or(defDuration),
};
std::vector<std::unique_ptr<ChangeRequest>> changes;
for (auto& kv : layersRemoved) {
kv.second->layerRemoved(changes);
}
for (auto& kv : layersAdded) {
kv.second->layerAdded(shaders, context, state, evalParameters, changes);
}
for (auto& impl : *layerImpls) {
impl->update(context, state, evalParameters, changes);
}
@@ -808,7 +806,7 @@ void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders,
void RenderOrchestrator::processChanges() {
auto localChanges = std::move(pendingChanges);
for (auto &change : localChanges) {
for (auto& change : localChanges) {
change->execute(*this);
}
}

View File

@@ -35,11 +35,11 @@ class CrossTileSymbolIndex;
class RenderTree;
namespace gfx {
class Drawable;
class ShaderRegistry;
class Drawable;
class ShaderRegistry;
using DrawablePtr = std::shared_ptr<Drawable>;
} // namespace gfx
using DrawablePtr = std::shared_ptr<Drawable>;
} // namespace gfx
namespace style {
class LayerProperties;

View File

@@ -104,7 +104,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
staticData->upload(*uploadPass);
renderTree.getLineAtlas().upload(*uploadPass);
renderTree.getPatternAtlas().upload(*uploadPass);
for (const auto& pair : orchestrator.getDrawables()) {
auto& drawable = *pair.second;
@@ -117,35 +117,30 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
auto& shader = drawable.getShader();
// Generate a vertex array object for the drawable state, if necessary
if (shader && (!drawableGL.getVertexArray().isValid() ||
drawableGL.getVertexAttributes().isDirty())) {
if (shader && (!drawableGL.getVertexArray().isValid() || drawableGL.getVertexAttributes().isDirty())) {
const auto usage = gfx::BufferUsageType::StaticDraw;
// Build index buffer
const auto& indexData = drawable.getIndexData();
auto indexBuffer = gfx::IndexBuffer {
auto indexBuffer = gfx::IndexBuffer{
indexData.size(),
uploadPass->createIndexBufferResource(
indexData.data(),
indexData.size() * sizeof(indexData[0]),
usage)
};
indexData.data(), indexData.size() * sizeof(indexData[0]), usage)};
// Apply drawable values to shader defaults
const auto& defaults = shader->getVertexAttributes();
const auto& overrides = drawable.getVertexAttributes();
const auto vertexCount = drawable.getVertexCount();
std::unique_ptr<gfx::VertexBufferResource> vertexBuffer;
auto bindings = uploadPass->buildAttributeBindings(vertexCount, defaults, overrides, usage, vertexBuffer);
auto bindings = uploadPass->buildAttributeBindings(
vertexCount, defaults, overrides, usage, vertexBuffer);
auto& glContext = static_cast<gl::Context&>(context);
auto vertexArray = glContext.createVertexArray();
vertexArray.bind(glContext, indexBuffer, bindings);
glContext.bindVertexArray = gl::value::BindVertexArray::Default;
drawableGL.setVertexArray(std::move(vertexArray),
std::move(vertexBuffer),
std::move(indexBuffer));
drawableGL.setVertexArray(std::move(vertexArray), std::move(vertexBuffer), std::move(indexBuffer));
}
}
}
@@ -203,7 +198,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
parameters.depthRangeSize = 1 - (1 + 2) * parameters.numSublayers * parameters.depthEpsilon;
const auto debugGroup(parameters.renderPass->createDebugGroup("drawables"));
for (const auto &pair : orchestrator.getDrawables()) {
for (const auto& pair : orchestrator.getDrawables()) {
const auto& drawable = *pair.second;
if (!context.setupDraw(parameters, drawable)) {
@@ -234,7 +229,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
// - OPAQUE PASS -------------------------------------------------------------------------------
// Render everything top-to-bottom by using reverse iterators. Render opaque objects first.
{
parameters.pass = RenderPass::Opaque;
const auto debugGroup(parameters.renderPass->createDebugGroup("opaque"));

View File

@@ -14,58 +14,72 @@ namespace gl {
static gfx::AttributeDataType mapType(platform::GLenum attrType) {
using T = gfx::AttributeDataType;
switch (attrType) {
case GL_FLOAT: return T::Float;
case GL_FLOAT_VEC2: return T::Float2;
case GL_FLOAT_VEC3: return T::Float3;
case GL_FLOAT_VEC4: return T::Float4;
case GL_FLOAT_MAT2: return T::Float4; // does that work ?
case GL_FLOAT:
return T::Float;
case GL_FLOAT_VEC2:
return T::Float2;
case GL_FLOAT_VEC3:
return T::Float3;
case GL_FLOAT_VEC4:
return T::Float4;
case GL_FLOAT_MAT2:
return T::Float4; // does that work ?
case GL_FLOAT_MAT3:
case GL_FLOAT_MAT4: return T::Float4;
case GL_INT: return T::Int;
case GL_INT_VEC2: return T::Int2;
case GL_INT_VEC3: return T::Int3;
case GL_INT_VEC4: return T::Int4;
case GL_UNSIGNED_INT: return T::UInt;
case GL_FLOAT_MAT4:
return T::Float4;
case GL_INT:
return T::Int;
case GL_INT_VEC2:
return T::Int2;
case GL_INT_VEC3:
return T::Int3;
case GL_INT_VEC4:
return T::Int4;
case GL_UNSIGNED_INT:
return T::UInt;
// ES3 stuff that isn't defined yet:
//case GL_FLOAT_MAT2x3:
//case GL_FLOAT_MAT2x4:
//case GL_FLOAT_MAT3x2:
//case GL_FLOAT_MAT3x4:
//case GL_FLOAT_MAT4x2:
//case GL_FLOAT_MAT4x3: return T::Invalid;
//case GL_UNSIGNED_INT_VEC2: return T::UInt2;
//case GL_UNSIGNED_INT_VEC3: return T::UInt3;
//case GL_UNSIGNED_INT_VEC4: return T::UInt4;
//case GL_DOUBLE: return T::Float;
//case GL_DOUBLE_VEC2: return T::Float2;
//case GL_DOUBLE_VEC3: return T::Float3;
//case GL_DOUBLE_VEC4: return T::Float4;
//case GL_DOUBLE_MAT2: return T::Float4;
//case GL_DOUBLE_MAT3:
//case GL_DOUBLE_MAT4:
//case GL_DOUBLE_MAT2x3:
//case GL_DOUBLE_MAT2x4:
//case GL_DOUBLE_MAT3x2:
//case GL_DOUBLE_MAT3x4:
//case GL_DOUBLE_MAT4x2:
//case GL_DOUBLE_MAT4x3:
default: return T::Invalid;
// case GL_FLOAT_MAT2x3:
// case GL_FLOAT_MAT2x4:
// case GL_FLOAT_MAT3x2:
// case GL_FLOAT_MAT3x4:
// case GL_FLOAT_MAT4x2:
// case GL_FLOAT_MAT4x3: return T::Invalid;
// case GL_UNSIGNED_INT_VEC2: return T::UInt2;
// case GL_UNSIGNED_INT_VEC3: return T::UInt3;
// case GL_UNSIGNED_INT_VEC4: return T::UInt4;
// case GL_DOUBLE: return T::Float;
// case GL_DOUBLE_VEC2: return T::Float2;
// case GL_DOUBLE_VEC3: return T::Float3;
// case GL_DOUBLE_VEC4: return T::Float4;
// case GL_DOUBLE_MAT2: return T::Float4;
// case GL_DOUBLE_MAT3:
// case GL_DOUBLE_MAT4:
// case GL_DOUBLE_MAT2x3:
// case GL_DOUBLE_MAT2x4:
// case GL_DOUBLE_MAT3x2:
// case GL_DOUBLE_MAT3x4:
// case GL_DOUBLE_MAT4x2:
// case GL_DOUBLE_MAT4x3:
default:
return T::Invalid;
}
}
// No `AttributeDataType` for 4x4, so we have to account for it separately...
static int mapCount(const platform::GLenum attrType) {
switch (attrType) {
case GL_FLOAT_MAT3: return 3;
case GL_FLOAT_MAT4: return 4;
default: return 1;
case GL_FLOAT_MAT3:
return 3;
case GL_FLOAT_MAT4:
return 4;
default:
return 1;
}
}
ShaderProgramGL::ShaderProgramGL(UniqueProgram&& glProgram_)
: ShaderProgramBase(),
glProgram(std::move(glProgram_)) {
}
glProgram(std::move(glProgram_)) {}
ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program,
VertexAttributeArrayGL&& uniforms_,
@@ -73,20 +87,18 @@ ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program,
: ShaderProgramBase(),
glProgram(std::move(program)),
uniforms(std::move(uniforms_)),
vertexAttributes(std::move(attributes_)) {
}
vertexAttributes(std::move(attributes_)) {}
ShaderProgramGL::ShaderProgramGL(ShaderProgramGL&& other)
: ShaderProgramBase(std::forward<ShaderProgramBase&&>(other)),
glProgram(std::move(other.glProgram)),
uniforms(std::move(other.uniforms)),
vertexAttributes(std::move(other.vertexAttributes)) {
}
vertexAttributes(std::move(other.vertexAttributes)) {}
using namespace platform;
static void addAttr(VertexAttributeArrayGL& attrs, const char* name, GLint index,
GLsizei length, GLint count, GLenum glType) {
static void addAttr(
VertexAttributeArrayGL& attrs, const char* name, GLint index, GLsizei length, GLint count, GLenum glType) {
const auto elementType = mapType(glType);
const auto elementCount = mapCount(glType); // number of `elementType`, hopefully temporary
if (elementType != gfx::AttributeDataType::Invalid && length > 0) {
@@ -97,22 +109,21 @@ static void addAttr(VertexAttributeArrayGL& attrs, const char* name, GLint index
}
}
std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
Context& context,
std::string_view /*name*/,
std::string_view vertexSource,
std::string_view fragmentSource) noexcept(false) {
std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(Context& context,
std::string_view /*name*/,
std::string_view vertexSource,
std::string_view fragmentSource) noexcept(false) {
const auto firstAttrib = "a_pos";
// throws on compile error
auto vertProg = context.createShader(ShaderType::Vertex, std::initializer_list<const char*>{vertexSource.data()});
auto fragProg = context.createShader(ShaderType::Fragment, std::initializer_list<const char*>{fragmentSource.data()});
auto fragProg = context.createShader(ShaderType::Fragment,
std::initializer_list<const char*>{fragmentSource.data()});
auto program = context.createProgram(vertProg, fragProg, firstAttrib);
// GLES3.1
//GLint numAttribs;
//glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs);
// GLint numAttribs;
// glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs);
VertexAttributeArrayGL uniforms;

View File

@@ -3,9 +3,9 @@
namespace mbgl {
namespace mtl {
//bool ShaderProgramMTL::compile(std::string_view vert, std::string_view frag) {
// return false;
//}
// bool ShaderProgramMTL::compile(std::string_view vert, std::string_view frag) {
// return false;
// }
} // namespace mtl
} // namespace mbgl

View File

@@ -1,4 +1,3 @@
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/gfx/vertex_attribute.hpp>

View File

@@ -66,14 +66,14 @@ public:
virtual void update(gfx::Context&,
const TransformState&,
const PropertyEvaluationParameters&,
UniqueChangeRequestVec&) const { }
UniqueChangeRequestVec&) const {}
virtual void layerAdded(gfx::ShaderRegistry&,
gfx::Context&,
const TransformState&,
const PropertyEvaluationParameters&,
UniqueChangeRequestVec&) const { }
virtual void layerRemoved(UniqueChangeRequestVec&) const { }
UniqueChangeRequestVec&) const {}
virtual void layerRemoved(UniqueChangeRequestVec&) const {}
std::string id;
std::string source;

View File

@@ -5,8 +5,8 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/renderer/change_request.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
//#include <mbgl/shaders/gl/shader_program_gl.hpp>
//#include <mbgl/shaders/gl/shader_program_gl.hpp>
// #include <mbgl/shaders/gl/shader_program_gl.hpp>
// #include <mbgl/shaders/gl/shader_program_gl.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/util/logging.hpp>
@@ -17,13 +17,11 @@
namespace mbgl {
namespace style {
BackgroundLayer::Impl::Impl(const Impl& other) :
Layer::Impl(other),
tileDrawables(other.tileDrawables),
lastColor(other.lastColor),
paint(other.paint)
{
}
BackgroundLayer::Impl::Impl(const Impl& other)
: Layer::Impl(other),
tileDrawables(other.tileDrawables),
lastColor(other.lastColor),
paint(other.paint) {}
bool BackgroundLayer::Impl::hasLayoutDifference(const Layer::Impl&) const {
return false;
@@ -55,8 +53,7 @@ void BackgroundLayer::Impl::layerRemoved(UniqueChangeRequestVec& changes) const
}
removeDrawables<decltype(localDrawables)::const_iterator>(
localDrawables.cbegin(), localDrawables.cend(), changes,
[](auto& ii) { return ii->second->getId(); });
localDrawables.cbegin(), localDrawables.cend(), changes, [](auto& ii) { return ii->second->getId(); });
}
void BackgroundLayer::Impl::update(gfx::Context& context,
@@ -71,7 +68,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
const auto evaluated = unevaluated->evaluate(evalParameters);
// TODO: If background is solid, we can skip drawables and rely on the clear color
//const auto passes = eval.get<style::BackgroundOpacity>() == 0.0f
// const auto passes = eval.get<style::BackgroundOpacity>() == 0.0f
// ? RenderPass::None
// : (!uneval.get<style::BackgroundPattern>().isUndefined()
// || eval.get<style::BackgroundOpacity>() < 1.0f
@@ -79,8 +76,8 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
// ? RenderPass::Translucent
// : RenderPass::Opaque | RenderPass::Translucent; // evaluated based on opaquePassCutoff in render()
//unevaluated.hasTransition();
//getCrossfade<BackgroundLayerProperties>(evaluatedProperties).t != 1;
// unevaluated.hasTransition();
// getCrossfade<BackgroundLayerProperties>(evaluatedProperties).t != 1;
std::optional<Color> color;
if (evaluated.get<BackgroundPattern>().from.empty()) {
@@ -93,8 +90,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
// If the result is transparent or missing, just remove any existing drawables and stop
if (!color) {
removeDrawables<decltype(tileDrawables)::const_iterator>(
tileDrawables.cbegin(), tileDrawables.cend(), changes,
[](auto& ii) { return ii->second->getId(); });
tileDrawables.cbegin(), tileDrawables.cend(), changes, [](auto& ii) { return ii->second->getId(); });
tileDrawables.clear();
return;
}
@@ -106,7 +102,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
const auto tileCover = util::tileCover(state, zoom);
// Drawables per overscaled or canonical tile?
//const UnwrappedTileID unwrappedTileID = tileID.toUnwrapped();
// const UnwrappedTileID unwrappedTileID = tileID.toUnwrapped();
// Put the tile cover into a searchable form.
// TODO: Likely better to sort and `std::binary_search` the vector.
@@ -114,14 +110,15 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
const std::unordered_set<OverscaledTileID> newTileIDs(tileCover.begin(), tileCover.end());
// For each existing tile drawable...
for (auto iter = tileDrawables.begin(); iter != tileDrawables.end(); ) {
for (auto iter = tileDrawables.begin(); iter != tileDrawables.end();) {
const auto& drawable = iter->second;
// Has this tile dropped out of the cover set?
if (newTileIDs.find(iter->first) == newTileIDs.end()) {
// remove it
changes.emplace_back(std::make_unique<RemoveDrawableRequest>(drawable->getId()));
//Log::Warning(Event::General, "Removing drawable for " + util::toString(iter->first) + " total " + std::to_string(stats.tileDrawablesRemoved+1));
// Log::Warning(Event::General, "Removing drawable for " + util::toString(iter->first) + " total " +
// std::to_string(stats.tileDrawablesRemoved+1));
iter = tileDrawables.erase(iter);
++stats.tileDrawablesRemoved;
continue;
@@ -158,7 +155,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
// Tile coordinates are fixed...
builder->addQuad(0, 0, util::EXTENT, util::EXTENT);
// ... they're placed with the matrix in the uniforms, which changes with the view
builder->setMatrix(/*parameters.matrixForTile(tileID.toUnwrapped())*/ matrix::identity4());
@@ -171,7 +168,8 @@ void BackgroundLayer::Impl::update(gfx::Context& context,
result.first->second = drawable;
changes.emplace_back(std::make_unique<AddDrawableRequest>(std::move(drawable)));
++stats.tileDrawablesAdded;
//Log::Warning(Event::General, "Adding drawable for " + util::toString(tileID) + " total " + std::to_string(stats.tileDrawablesAdded+1));
// Log::Warning(Event::General, "Adding drawable for " + util::toString(tileID) + " total " +
// std::to_string(stats.tileDrawablesAdded+1));
}
}
}

View File

@@ -49,7 +49,9 @@ public:
private:
// Add a deletion change request for each drawable in a collection
template <typename T>
static void removeDrawables(T beg, const T end, UniqueChangeRequestVec& changes,
static void removeDrawables(T beg,
const T end,
UniqueChangeRequestVec& changes,
std::function<util::SimpleIdentity(const T&)> f) {
for (; beg != end; ++beg) {
changes.emplace_back(std::make_unique<RemoveDrawableRequest>(f(beg)));

View File

@@ -3,9 +3,9 @@
#include <atomic>
namespace {
// This is not in the class declaration to minimize include dependencies
std::atomic<std::int64_t> nextId = 1;
} // anonymous namespace
// This is not in the class declaration to minimize include dependencies
std::atomic<std::int64_t> nextId = 1;
} // anonymous namespace
namespace mbgl {
namespace util {
@@ -13,11 +13,7 @@ namespace util {
const SimpleIdentity SimpleIdentity::Empty = {emptyID};
SimpleIdentity::SimpleIdentity()
: uniqueID(nextId++)
{
}
: uniqueID(nextId++) {}
} // namespace util
} // namespace mbgl

View File

@@ -33,8 +33,12 @@ using matf4 = std::array<float, 16>;
namespace matrix {
void identity(mat4& out);
constexpr mat4 identity4() { return { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 }; }
constexpr matf4 identity4f() { return { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 }; }
constexpr mat4 identity4() {
return {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
}
constexpr matf4 identity4f() {
return {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
}
bool invert(mat4& out, const mat4& a);
void ortho(mat4& out, double left, double right, double bottom, double top, double near, double far);