mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
Merge branch 'master' into feature/grid-labels
* Solve conflict in renderablegrid.h
This commit is contained in:
@@ -42,6 +42,12 @@ namespace {
|
||||
"This value determines the color of the grid lines that are rendered"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo HighlightColorInfo = {
|
||||
"HighlightColor",
|
||||
"Highlight Color",
|
||||
"This value determines the color of the highlighted lines in the grid"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo SegmentsInfo = {
|
||||
"Segments",
|
||||
"Number of Segments",
|
||||
@@ -49,12 +55,26 @@ namespace {
|
||||
"grid in each direction"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo HighlightRateInfo = {
|
||||
"HighlightRate",
|
||||
"Highlight Rate",
|
||||
"The rate that the columns and rows are highlighted, counted with respect to the "
|
||||
"center of the grid. If the number of segments in the grid is odd, the "
|
||||
"highlighting might be offset from the center."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = {
|
||||
"LineWidth",
|
||||
"Line Width",
|
||||
"This value specifies the line width of the grid"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo HighlightLineWidthInfo = {
|
||||
"HighlightLineWidth",
|
||||
"HighlightLine Width",
|
||||
"This value specifies the line width of the highlighted lines in the grid"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo SizeInfo = {
|
||||
"Size",
|
||||
"Grid Size",
|
||||
@@ -78,12 +98,21 @@ namespace {
|
||||
// [[codegen::verbatim(ColorInfo.description)]]
|
||||
std::optional<glm::vec3> color [[codegen::color()]];
|
||||
|
||||
// [[codegen::verbatim(HighlightColorInfo.description)]]
|
||||
std::optional<glm::vec3> highlightColor [[codegen::color()]];
|
||||
|
||||
// [[codegen::verbatim(SegmentsInfo.description)]]
|
||||
std::optional<glm::ivec2> segments;
|
||||
|
||||
// [[codegen::verbatim(HighlightRateInfo.description)]]
|
||||
std::optional<glm::ivec2> highlightRate;
|
||||
|
||||
// [[codegen::verbatim(LineWidthInfo.description)]]
|
||||
std::optional<float> lineWidth;
|
||||
|
||||
// [[codegen::verbatim(HighlightLineWidthInfo.description)]]
|
||||
std::optional<float> highlightLineWidth;
|
||||
|
||||
// [[codegen::verbatim(SizeInfo.description)]]
|
||||
std::optional<glm::vec2> size;
|
||||
|
||||
@@ -106,8 +135,11 @@ documentation::Documentation RenderableGrid::Documentation() {
|
||||
RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _color(ColorInfo, glm::vec3(0.5f), glm::vec3(0.f), glm::vec3(1.f))
|
||||
, _highlightColor(HighlightColorInfo, glm::vec3(0.8f), glm::vec3(0.f), glm::vec3(1.f))
|
||||
, _segments(SegmentsInfo, glm::uvec2(10), glm::uvec2(1), glm::uvec2(200))
|
||||
, _highlightRate(HighlightRateInfo, glm::uvec2(0), glm::uvec2(0), glm::uvec2(200))
|
||||
, _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f)
|
||||
, _highlightLineWidth(HighlightLineWidthInfo, 0.5f, 1.f, 20.f)
|
||||
, _size(SizeInfo, glm::vec2(1.f), glm::vec2(1.f), glm::vec2(1e11f))
|
||||
, _drawLabels(DrawLabelInfo, false)
|
||||
{
|
||||
@@ -120,13 +152,26 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary)
|
||||
_color.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_color);
|
||||
|
||||
// If no highlight color is specified then use the base color
|
||||
_highlightColor = p.highlightColor.value_or(_color);
|
||||
_highlightColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_highlightColor);
|
||||
|
||||
_segments = p.segments.value_or(_segments);
|
||||
_segments.onChange([&]() { _gridIsDirty = true; });
|
||||
addProperty(_segments);
|
||||
|
||||
_highlightRate = p.highlightRate.value_or(_highlightRate);
|
||||
_highlightRate.onChange([&]() { _gridIsDirty = true; });
|
||||
addProperty(_highlightRate);
|
||||
|
||||
_lineWidth = p.lineWidth.value_or(_lineWidth);
|
||||
addProperty(_lineWidth);
|
||||
|
||||
// If no highlight line width is specified then use the base line width
|
||||
_highlightLineWidth = p.highlightLineWidth.value_or(_lineWidth);
|
||||
addProperty(_highlightLineWidth);
|
||||
|
||||
_size.setExponent(10.f);
|
||||
_size = p.size.value_or(_size);
|
||||
_size.onChange([&]() { _gridIsDirty = true; });
|
||||
@@ -172,9 +217,14 @@ void RenderableGrid::initializeGL() {
|
||||
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
glGenBuffers(1, &_vBufferID);
|
||||
glGenVertexArrays(1, &_highlightVaoID);
|
||||
glGenBuffers(1, &_highlightVBufferID);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBindVertexArray(_highlightVaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _highlightVBufferID);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
@@ -182,9 +232,13 @@ void RenderableGrid::initializeGL() {
|
||||
void RenderableGrid::deinitializeGL() {
|
||||
glDeleteVertexArrays(1, &_vaoID);
|
||||
_vaoID = 0;
|
||||
glDeleteVertexArrays(1, &_highlightVaoID);
|
||||
_highlightVaoID = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vBufferID);
|
||||
_vBufferID = 0;
|
||||
glDeleteBuffers(1, &_highlightVBufferID);
|
||||
_highlightVBufferID = 0;
|
||||
|
||||
BaseModule::ProgramObjectManager.release(
|
||||
"GridProgram",
|
||||
@@ -201,7 +255,7 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){
|
||||
glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
|
||||
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
|
||||
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
|
||||
glm::scale(glm::dmat4(1.0), data.modelTransform.scale);
|
||||
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
@@ -225,13 +279,24 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glDepthMask(false);
|
||||
|
||||
// Render minor grid
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(_mode, 0, static_cast<GLsizei>(_varray.size()));
|
||||
glBindVertexArray(0);
|
||||
|
||||
_gridProgram->deactivate();
|
||||
// Render major grid
|
||||
#ifndef __APPLE__
|
||||
glLineWidth(_highlightLineWidth);
|
||||
#else
|
||||
glLineWidth(1.f);
|
||||
#endif
|
||||
_gridProgram->setUniform("gridColor", _highlightColor);
|
||||
|
||||
glBindVertexArray(_highlightVaoID);
|
||||
glDrawArrays(_mode, 0, static_cast<GLsizei>(_highlightArray.size()));
|
||||
|
||||
// Restore GL State
|
||||
glBindVertexArray(0);
|
||||
_gridProgram->deactivate();
|
||||
global::renderEngine->openglStateCache().resetBlendState();
|
||||
global::renderEngine->openglStateCache().resetLineState();
|
||||
global::renderEngine->openglStateCache().resetDepthState();
|
||||
@@ -262,50 +327,109 @@ void RenderableGrid::update(const UpdateData&) {
|
||||
return;
|
||||
}
|
||||
|
||||
const glm::vec2 halfSize = _size.value() / 2.f;
|
||||
const glm::dvec2 halfSize = static_cast<glm::dvec2>(_size.value()) / 2.0;
|
||||
const glm::uvec2 nSegments = _segments.value();
|
||||
const glm::vec2 step = _size.value() / static_cast<glm::vec2>(nSegments);
|
||||
const glm::dvec2 step =
|
||||
static_cast<glm::dvec2>(_size.value()) / static_cast<glm::dvec2>(nSegments);
|
||||
|
||||
const int nLines = (2 * nSegments.x * nSegments.y) + nSegments.x + nSegments.y;
|
||||
const int nVertices = 2 * nLines;
|
||||
_varray.resize(nVertices);
|
||||
_varray.clear();
|
||||
_varray.reserve(nVertices);
|
||||
_highlightArray.clear();
|
||||
_highlightArray.reserve(nVertices);
|
||||
// OBS! Could be optimized further by removing duplicate vertices
|
||||
|
||||
int nr = 0;
|
||||
// If the number of segments are uneven the center won't be completly centered
|
||||
const glm::uvec2 center = glm::uvec2(nSegments.x / 2.f, nSegments.y / 2.f);
|
||||
for (unsigned int i = 0; i < nSegments.x; ++i) {
|
||||
for (unsigned int j = 0; j < nSegments.y; ++j) {
|
||||
const float y0 = -halfSize.y + j * step.y;
|
||||
const float y1 = y0 + step.y;
|
||||
const double y0 = -halfSize.y + j * step.y;
|
||||
const double y1 = y0 + step.y;
|
||||
|
||||
const float x0 = -halfSize.x + i * step.x;
|
||||
const float x1 = x0 + step.x;
|
||||
const double x0 = -halfSize.x + i * step.x;
|
||||
const double x1 = x0 + step.x;
|
||||
|
||||
_varray[nr++] = { x0, y0, 0.f };
|
||||
_varray[nr++] = { x0, y1, 0.f };
|
||||
// Line in y direction
|
||||
bool shouldHighlight = false;
|
||||
if (_highlightRate.value().y != 0) {
|
||||
int rest = static_cast<int>(i - center.y) % _highlightRate.value().y;
|
||||
shouldHighlight = abs(rest) == 0;
|
||||
}
|
||||
|
||||
_varray[nr++] = { x0, y0, 0.f };
|
||||
_varray[nr++] = { x1, y0, 0.f };
|
||||
if (shouldHighlight) {
|
||||
_highlightArray.push_back({ x0, y0, 0.0 });
|
||||
_highlightArray.push_back({ x0, y1, 0.0 });
|
||||
}
|
||||
else {
|
||||
_varray.push_back({ x0, y0, 0.0 });
|
||||
_varray.push_back({ x0, y1, 0.0 });
|
||||
}
|
||||
|
||||
// Line in x direction
|
||||
shouldHighlight = false;
|
||||
if (_highlightRate.value().x != 0) {
|
||||
int rest = static_cast<int>(j - center.x) % _highlightRate.value().x;
|
||||
shouldHighlight = abs(rest) == 0;
|
||||
}
|
||||
|
||||
if (shouldHighlight) {
|
||||
_highlightArray.push_back({ x0, y0, 0.0 });
|
||||
_highlightArray.push_back({ x1, y0, 0.0 });
|
||||
}
|
||||
else {
|
||||
_varray.push_back({ x0, y0, 0.0 });
|
||||
_varray.push_back({ x1, y0, 0.0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// last x row
|
||||
for (unsigned int i = 0; i < nSegments.x; ++i) {
|
||||
const float x0 = -halfSize.x + i * step.x;
|
||||
const float x1 = x0 + step.x;
|
||||
_varray[nr++] = { x0, halfSize.y, 0.f };
|
||||
_varray[nr++] = { x1, halfSize.y, 0.f };
|
||||
const double x0 = -halfSize.x + i * step.x;
|
||||
const double x1 = x0 + step.x;
|
||||
|
||||
bool shouldHighlight = false;
|
||||
if (_highlightRate.value().x != 0) {
|
||||
int rest =
|
||||
static_cast<int>(nSegments.y - center.x) % _highlightRate.value().x;
|
||||
shouldHighlight = abs(rest) == 0;
|
||||
}
|
||||
|
||||
if (shouldHighlight) {
|
||||
_highlightArray.push_back({ x0, halfSize.y, 0.0 });
|
||||
_highlightArray.push_back({ x1, halfSize.y, 0.0 });
|
||||
}
|
||||
else {
|
||||
_varray.push_back({ x0, halfSize.y, 0.0 });
|
||||
_varray.push_back({ x1, halfSize.y, 0.0 });
|
||||
}
|
||||
}
|
||||
|
||||
// last y col
|
||||
for (unsigned int i = 0; i < nSegments.y; ++i) {
|
||||
const float y0 = -halfSize.y + i * step.y;
|
||||
const float y1 = y0 + step.y;
|
||||
_varray[nr++] = { halfSize.x, y0, 0.f };
|
||||
_varray[nr++] = { halfSize.x, y1, 0.f };
|
||||
const double y0 = -halfSize.y + i * step.y;
|
||||
const double y1 = y0 + step.y;
|
||||
|
||||
bool shouldHighlight = false;
|
||||
if (_highlightRate.value().y != 0) {
|
||||
int rest =
|
||||
static_cast<int>(nSegments.x - center.y) % _highlightRate.value().y;
|
||||
shouldHighlight = abs(rest) == 0;
|
||||
}
|
||||
if (shouldHighlight) {
|
||||
_highlightArray.push_back({ halfSize.x, y0, 0.0 });
|
||||
_highlightArray.push_back({ halfSize.x, y1, 0.0 });
|
||||
}
|
||||
else {
|
||||
_varray.push_back({ halfSize.x, y0, 0.0 });
|
||||
_varray.push_back({ halfSize.x, y1, 0.0 });
|
||||
}
|
||||
}
|
||||
|
||||
setBoundingSphere(glm::length(glm::dvec2(halfSize)));
|
||||
|
||||
// Minor grid
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferData(
|
||||
@@ -314,8 +438,19 @@ void RenderableGrid::update(const UpdateData&) {
|
||||
_varray.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), nullptr);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);
|
||||
// Major grid
|
||||
glBindVertexArray(_highlightVaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _highlightVBufferID);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_highlightArray.size() * sizeof(Vertex),
|
||||
_highlightArray.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), nullptr);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user