This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Improve attribute binding API
- Loading branch information
1 parent
b9b8657
commit e4310aa
Showing
45 changed files
with
258 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <mbgl/gl/types.hpp> | ||
#include <mbgl/gl/shader.hpp> | ||
|
||
#include <cstddef> | ||
#include <limits> | ||
#include <vector> | ||
|
||
namespace mbgl { | ||
namespace gl { | ||
|
||
template <typename T, std::size_t N> | ||
class Attribute { | ||
public: | ||
Attribute(const char* name, const Shader& shader) | ||
: location(shader.getAttributeLocation(name)) {} | ||
|
||
AttributeLocation location; | ||
}; | ||
|
||
class AttributeBinding { | ||
public: | ||
template <class Vertex, class T, std::size_t N, std::size_t O> | ||
AttributeBinding(const T (Vertex::*)[N], const Attribute<T, N>& attribute, std::integral_constant<std::size_t, O>) | ||
: location(attribute.location), | ||
type(DataTypeOf<T>::value), | ||
count(N), | ||
offset(O) { | ||
static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout"); | ||
static_assert(O % 4 == 0, "vertex attribute must be optimally aligned"); | ||
static_assert(1 <= N && N <= 4, "count must be 1, 2, 3, or 4"); | ||
static_assert(sizeof(Vertex) <= std::numeric_limits<int32_t>::max(), "vertex type is too big"); | ||
} | ||
|
||
AttributeLocation location; | ||
DataType type; | ||
uint8_t count; | ||
std::size_t offset; | ||
}; | ||
|
||
#define MBGL_MAKE_ATTRIBUTE_BINDING(Vertex, shader, name) \ | ||
::mbgl::gl::AttributeBinding(&Vertex::name, \ | ||
shader.name, \ | ||
std::integral_constant<std::size_t, offsetof(Vertex, name)>()) | ||
|
||
template <class Shader, class Vertex> struct AttributeBindings; | ||
|
||
} // namespace gl | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
#include <mbgl/shader/circle_vertex.hpp> | ||
#include <mbgl/gl/shader.hpp> | ||
#include <mbgl/gl/gl.hpp> | ||
|
||
namespace mbgl { | ||
|
||
void CircleVertex::bind(const int8_t* offset) { | ||
static_assert(sizeof(CircleVertex) == 4, "expected CircleVertex size"); | ||
|
||
MBGL_BIND_VERTEX_ATTRIBUTE(CircleVertex, a_pos, offset); | ||
} | ||
static_assert(sizeof(CircleVertex) == 4, "expected CircleVertex size"); | ||
|
||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
#include <mbgl/shader/collision_box_vertex.hpp> | ||
#include <mbgl/gl/shader.hpp> | ||
#include <mbgl/gl/gl.hpp> | ||
|
||
namespace mbgl { | ||
|
||
void CollisionBoxVertex::bind(const int8_t* offset) { | ||
static_assert(sizeof(CollisionBoxVertex) == 10, "expected CollisionBoxVertex size"); | ||
|
||
MBGL_BIND_VERTEX_ATTRIBUTE(CollisionBoxVertex, a_pos, offset); | ||
MBGL_BIND_VERTEX_ATTRIBUTE(CollisionBoxVertex, a_extrude, offset); | ||
MBGL_BIND_VERTEX_ATTRIBUTE(CollisionBoxVertex, a_data, offset); | ||
} | ||
static_assert(sizeof(CollisionBoxVertex) == 10, "expected CollisionBoxVertex size"); | ||
|
||
} // namespace mbgl |
Oops, something went wrong.