Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Shaders refactor #6856

Merged
merged 6 commits into from
Nov 8, 2016
Merged

Shaders refactor #6856

merged 6 commits into from
Nov 8, 2016

Conversation

jfirebaugh
Copy link
Contributor

@jfirebaugh jfirebaugh commented Oct 30, 2016

Followup to #6468, specifically #6468 (comment).

  • Fix overdraw debug mode

@mention-bot
Copy link

@jfirebaugh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kkaefer and @brunoabinader to be potential reviewers.

@brunoabinader
Copy link
Member

Potentially fixes the issues mentioned in #6799 (comment) (needs verification).

@jfirebaugh jfirebaugh force-pushed the shaders-refactor branch 5 times, most recently from 7facf12 to 4b8b19f Compare October 31, 2016 22:54
@jfirebaugh
Copy link
Contributor Author

Ready for review!

@jfirebaugh
Copy link
Contributor Author

@kkaefer The test sources now need the path for generated shader .hpp's in their include paths. Where in the cmake files do I change that?

@kkaefer
Copy link
Contributor

kkaefer commented Nov 3, 2016

You can add ${MBGL_GENERATED}/include to the include dir list. The actual code that generates the shaders is in cmake/shaders.cmake.

@jfirebaugh jfirebaugh force-pushed the shaders-refactor branch 2 times, most recently from 8cdf2ec to 8d201ab Compare November 3, 2016 18:36
@kkaefer
Copy link
Contributor

kkaefer commented Nov 4, 2016

I'd propose adding this to enforce initialization of the primitive types with a value:

diff --git a/src/mbgl/gl/draw_mode.hpp b/src/mbgl/gl/draw_mode.hpp
index 8f7db0a..b099a5f 100644
--- a/src/mbgl/gl/draw_mode.hpp
+++ b/src/mbgl/gl/draw_mode.hpp
@@ -11,6 +11,7 @@ public:
     using Primitive = Point;
     static constexpr std::size_t bufferGroupSize = 1;

+    Points(float pointSize_) : pointSize(pointSize_) {}
     float pointSize;
 };

@@ -19,6 +20,9 @@ public:
     using Primitive = Line;
     static constexpr std::size_t bufferGroupSize = 2;

+    Lines(float lineWidth_) : lineWidth(lineWidth_) {
+        assert(lineWidth > 0);
+    }
     float lineWidth;
 };

@@ -29,6 +33,9 @@ public:
     using Primitive = Line;
     static constexpr std::size_t bufferGroupSize = 1;

+    LineStrip(float lineWidth_) : lineWidth(lineWidth_) {
+        assert(lineWidth > 0);
+    }
     float lineWidth;
 };

}
};

} // namespace mgbl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problem does the indexed access solve here? It seems like the code worked before without this as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Less verbose -- std::get<typename As::SomeInnerType>(tuple) becomes tuple.template get<As>().
  • Eliminates the need to use a separate helper and std::index_sequence in Attributes::binder.
  • Will be consistent with use in [core] Properties refactor #6868.


std::size_t vertexLength;
std::size_t primitiveLength;
std::size_t indexLength;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why switch to indexLength? You're saying "Segment` now tracks offset and length of indices, rather than primitives. This is more natural.", but I'm unsure what "natural" is supposed to mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fundamentally, a vertex/index buffer is a buffer of vertices/indexes, not a buffer of triangles, or lines, or whatever. Conceptually, that's how OpenGL works, and I found it easier to reason about things when I stopped trying to think in terms of buffers of primitives.

Implementation wise, it simplifies calculations like this.

It matches the internal implementation of the new {Vertex,Index}Vector -- I think if we were to have std::vector<Triangle<Vertex>>, the packing might come out wrong. You don't want to get in a situation where there might be extra padding every third vertex. {Vertex,Index}Vector still enforces filling the vector with the right sized groups though.

//
template <class T> void ignore(const std::initializer_list<T>&) {}

} // namespace mbgl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move ignore to the mbgl::util namespace to avoid confusion with local variables or mistaking it for a language keyword?

@kkaefer
Copy link
Contributor

kkaefer commented Nov 4, 2016

One more thing that I'd like to see (but that is out of scope for this PR) is to somehow move shaders to the context. Background is that for Node.js, we'd like to use a shared context, and ideally we can share the shaders as well to avoid having all of these Programs that are just duplicates.

@jfirebaugh jfirebaugh force-pushed the shaders-refactor branch 2 times, most recently from b7f71e7 to f41e21d Compare November 4, 2016 21:45
}
};
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we factor out the attributes stuff into its own objects to be in line with the others?

@jfirebaugh
Copy link
Contributor Author

Rebasing this is getting to be a real drag. Can I get this approved and we can follow up on nits in other PRs?

@brunoabinader
Copy link
Member

Thank you @jfirebaugh - confirming that overdraw debug mode is operational again on Linux:
overdraw

…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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants