[core] Use gl::Program to resolve some rough edges in the GL binding types

* Extract `ignore` util to separate header.
* `Segment` now tracks offset and length of indices, rather than primitives. This is more natural.
* Introduce `VertexVector` and `IndexVector` types. These types carry information about the intended draw mode (`Triangles`, `LineStrip`, etc.), and ensure that elements are always appended in a group size appropriate for that draw mode, for both indexed and unindexed rendering.
* `Program`, rather than `Drawable`, is now the unifying object for draw calls. `Program` is the best place to type check the draw call, because it is typed to carry information about the intended primitive, vertex type, attributes, and uniforms.
* Use the debug shaders for debug tile rendering, like gl-js.
* Fix the draw mode for background. It was drawing triangle strips with a triangles array. Surprised this didn’t cause issues. Now it’s type checked.
This commit is contained in:
John Firebaugh
2016-11-07 12:26:05 -08:00
parent 66bdbc3b96
commit 1db2ffbc1b
42 changed files with 475 additions and 362 deletions

View File

@@ -16,6 +16,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_devicepixelratio);
class CircleProgram : public Program<
shaders::circle,
gl::Triangle,
gl::Attributes<
attributes::a_pos>,
gl::Uniforms<

View File

@@ -17,6 +17,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_maxzoom);
class CollisionBoxProgram : public Program<
shaders::collision_box,
gl::Line,
gl::Attributes<
attributes::a_pos,
attributes::a_extrude,

View File

@@ -0,0 +1,23 @@
#pragma once
#include <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shader/debug.hpp>
namespace mbgl {
class DebugProgram : public Program<
shaders::debug,
gl::Line,
gl::Attributes<
attributes::a_pos>,
gl::Uniforms<
uniforms::u_matrix,
uniforms::u_color>>
{
public:
using Program::Program;
};
} // namespace mbgl

View File

@@ -86,6 +86,7 @@ struct FillPatternUniforms : gl::Uniforms<
class FillProgram : public Program<
shaders::fill,
gl::Triangle,
FillAttributes,
FillUniforms>
{
@@ -94,6 +95,7 @@ class FillProgram : public Program<
class FillPatternProgram : public Program<
shaders::fill_pattern,
gl::Triangle,
FillAttributes,
FillPatternUniforms>
{
@@ -102,6 +104,7 @@ class FillPatternProgram : public Program<
class FillOutlineProgram : public Program<
shaders::fill_outline,
gl::Line,
FillAttributes,
FillUniforms>
{
@@ -110,6 +113,7 @@ class FillOutlineProgram : public Program<
class FillOutlinePatternProgram : public Program<
shaders::fill_outline_pattern,
gl::Line,
FillAttributes,
FillPatternUniforms>
{

View File

@@ -88,6 +88,7 @@ using LineVertex = LineAttributes::Vertex;
class LineProgram : public Program<
shaders::line,
gl::Triangle,
LineAttributes,
gl::Uniforms<
uniforms::u_matrix,
@@ -113,6 +114,7 @@ public:
class LinePatternProgram : public Program<
shaders::line_pattern,
gl::Triangle,
LineAttributes,
gl::Uniforms<
uniforms::u_matrix,
@@ -147,6 +149,7 @@ public:
class LineSDFProgram : public Program<
shaders::line_sdf,
gl::Triangle,
LineAttributes,
gl::Uniforms<
uniforms::u_matrix,

View File

@@ -11,11 +11,13 @@ enum class ProgramDefines : bool {
Overdraw = true,
};
template <class Shaders, class As, class Us>
class Program : public gl::Program<As, Us> {
template <class Shaders, class Primitive, class Attributes, class Uniforms>
class Program : public gl::Program<Primitive, Attributes, Uniforms> {
public:
using ParentType = gl::Program<Primitive, Attributes, Uniforms>;
Program(gl::Context& context, ProgramDefines defines)
: gl::Program<As, Us>(context, Shaders::vertexSource, fragmentSource(defines))
: ParentType(context, Shaders::vertexSource, fragmentSource(defines))
{}
static std::string fragmentSource(ProgramDefines defines) {

View File

@@ -5,6 +5,7 @@
#include <mbgl/programs/line_program.hpp>
#include <mbgl/programs/raster_program.hpp>
#include <mbgl/programs/symbol_program.hpp>
#include <mbgl/programs/debug_program.hpp>
#include <mbgl/programs/collision_box_program.hpp>
namespace mbgl {
@@ -24,6 +25,7 @@ public:
symbolIcon(context, defines),
symbolIconSDF(context, defines),
symbolGlyph(context, defines),
debug(context, ProgramDefines::None),
collisionBox(context, ProgramDefines::None) {
}
@@ -40,6 +42,7 @@ public:
SymbolSDFProgram symbolIconSDF;
SymbolSDFProgram symbolGlyph;
DebugProgram debug;
CollisionBoxProgram collisionBox;
};

View File

@@ -25,6 +25,7 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_tl_parent);
class RasterProgram : public Program<
shaders::raster,
gl::Triangle,
gl::Attributes<
attributes::a_pos,
attributes::a_texture_pos>,

View File

@@ -72,6 +72,7 @@ using SymbolVertex = SymbolAttributes::Vertex;
class SymbolIconProgram : public Program<
shaders::symbol_icon,
gl::Triangle,
SymbolAttributes,
gl::Uniforms<
uniforms::u_matrix,
@@ -95,6 +96,7 @@ public:
class SymbolSDFProgram : public Program<
shaders::symbol_sdf,
gl::Triangle,
SymbolAttributes,
gl::Uniforms<
uniforms::u_matrix,